Python 7.0pl5 Electronic Accessory User Manual


 
Socket Events
31
class Object(netsvc.Agent):
def __init__(self):
self.scheduleAction(self.daily,"00***","daily")
self.scheduleAction(self.weekly,"00**Sat","weekly")
self.scheduleAction(self.monthly,"001**","monthly")
self.scheduleAction(self.yearly,"0 0 1 Jan *","yearly")
self.scheduleAction(self.holiday,"0 0 25 Dec *","christmas")
def daily(self):
print "daily"
def weekly(self):
print "weekly"
def monthly(self):
print "monthly"
def yearly(self):
print "yearly"
def holiday(self,name):
print name
As a recurring action by nature will always run at some point in the future, you have to explicitly call
"cancelAction()" to stop it from running, even if it has already run at some point in time already.
If you make an error in the specification string such that it is invalid, no indication will be given and
the job will simply never be executed. The "cancelAllActions()" member function, as well as
cancelling actions associated with a once off call of a callback function, will also cancel all recurring
actions.
Socket Events
In an event driven system, it is important that any callback not unnecessarily block waiting for some-
thing to happen. If a callback does block, it prevents any other part of the system from doing some-
thing. The main reason which a callback may block is due to an attempt to read data from a socket when
there is no data waiting to be read. In an event driven system, an application should register interest in
the availability of data on a socket and only attempt to read data from the socket when it is known that
there is some available.
It is also advantageous in a event driven system for sockets to be placed into non blocking mode. When
a socket is in non blocking mode, if data is written to a socket and the socket is full an error is returned
indicating that the call would have blocked. The code can now register interest in the possibility of be-
ing able to write data to a socket and subsequently be notified when such a call would be successful.
In the mean time, other parts of the system can still do something.
To register interest in either of these events, the member function "subscribeSocket()" should
be used. The first argument to the function should be the callback function, the second argument the
socket descriptor and the third argument the type of events. If the third argument is not supplied, it will
default to SOCKET_POLLIN, indicating interest in the availability of data on a socket for reading.