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
Pavlos Christoforou wrote:
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.
This does have to be handled carefully. It will become much easier in Zope 2 (with the thing formerly known as BoboPOS3), but it is reasonably straightforward now. The way we've done this in the past is to define an application lock and set the acquire and release methods of the lock to __bobo_before__ and __bobo_after__ in the published module (Main in the Zope Framework), so that they get called by Bobo^H^H^H^HZPublisher when it handles a request. Then, when the scheduler needs to access application objects, it acquires the application lock with __bobo_before__ and releases it with __bobo_after__, just like ZPublisher does. You can see remnants of this in the (mostly defunct) scheduler package. As I mentioned above, the thing FKA BoboPOS3 will make this much easier. In fact, it will eliminate the need for an application lock! Jim -- Jim Fulton mailto:jim@digicool.com Technical Director (888) 344-4332 Python Powered! Digital Creations http://www.digicool.com http://www.python.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
participants (2)
-
Jim Fulton -
Pavlos Christoforou