User manual

internal clock. The same
counter is used for all four
ming hooks.
pass
HOOK_STDIN
Called when “user
input” data is
received
data A data buffer
containing one or more
received characters.
@setHook(HOOK_STDIN)
def getInput(data):
pass
HOOK_STDOUT
Called when “user
output” data is sent
HOOK_STDOUT passes no
parameters.
@setHook(HOOK_STDOUT)
def printed():
pass
HOOK_RPC_SENT
Called when the
buffer for an
outgoing RPC call is
cleared
bufRef an integer
reference to the packet
that the RPC call aempted
to send. This integer will
correspond to the value
returned from getInfo(9)
when called immediately
aer an RPC call is made.
The receipt of a value from
HOOK_RPC_SENT does not
necessarily indicate that
the packet was sent and
received successfully. It is
an indicaon that SNAP has
completed processing the
packet.
@setHook(HOOK_RPC_SENT)
def rpcDone(bufRef):
pass
NOTE Time-triggered event handlers must run quickly, finishing well before the next me period occurs.
To ensure this, keep your mer handlers concise. There is no guarantee that a ming handler will run
precisely on schedule. If a SNAPpy funcon is running when the me hook would otherwise occur, the
running code will not be interrupted to run the mer hook code.
Within a SNAPpy script, there are two methods for specifying the correct handler for a given HOOK event:
The modern way @setHook()
Immediately before the roune that you want to be invoked, put a
@setHook(HOOK_xxx)
where HOOK_xxx is one of the predefined HOOK codes given previously. This method, known as using a
“funcon decorator,” is used in the samples provided above.
20 SNAP® Network Operang System