[Zope] - Events, Schedulers ...
Pavlos Christoforou
pavlos@gaaros.msrc.sunysb.edu
Wed, 9 Dec 1998 21:05:59 -0500 (EST)
I am thinking of implementing some kind of event loop in my bobo app
(maybe in Zope too) but ...
I don't know much about threads or signals.
Do win NT/95 support some simple signals like alarm?
I understand that having the eventloop running in a different thread can
be disastrous, since a function registered in the eventloop might fight
for the same resources as a function running in the main loop.
The simplest idea I could come up with is to create an event class that
has a method to register callbacks at specified times, similar to the one
written by Tim and available through ftp.python.org. However instead of
having an eventloop running, the method responsible for firing the events
will be published and called by Zope/Bobo through the webserver at regular
intervals.
Something like:
def _eventloop(self,seconds=60):
'''eventloop(self,seconds=60)
Treading event loop. Delay is set to seconds'''
while 1:
try:
##FireTimers checks all registered callbacks and fires
##those that have expired
urllib.urlopen(self.abs_path+'/eventloop/FireTimers')
except:
pass
time.sleep(seconds)
def start_daemons(self):
'''start_daemons(self)
fires up deamon servers (eventloop)'''
th=Thread(target=self._eventloop)
th.start()
I believe that this avoids any concurrency complications as each callback
function in the event class will be called through the web server in a
manner indistinguishable from any other normal client access. I have tried
it with simple callbacks and it seems to work fine. But as I mentioned
before I don't know much about threads so I would like the opinion of the
more knowledgable folk before I spend more time. Do you see any problems?
(apart from reduced time resolution).
Thanks
Pavlos