asyncore.loop As A Win32 Service

Giles Brown giles_brown at hotmail.com
Thu Mar 27 09:25:11 CET 2003


John Abel <johnfabel at btinternet.com> wrote in message news:<mailman.1048529848.24545.python-list at python.org>...
> I'm writing a service, and have come across a problem with 
> asyncore.loop.  There doesn't seem to be a way for it to interrupted, 
> when the service is issued a stop.  To get round this with a similar 
> program using SocketServer, before executing handle_request I checked 
> for connections with select.select().  The way I'm thinking of doing it, 
> is to override asyncore.loop, set an event, launch the new asyncore.loop 
> in a thread, and replace the while 1 in asyncore.loop with a check for 
> the event.  Does that sound about the right to go about it?

If you have a look at the medusa/thread/select_trigger.py file (get the
CVS one if possible as the release isn't very up to date) at:

http://sourceforge.net/projects/oedipus/

You will see another way of doing it.  This uses a trick where the
code internally sets up a pair of connected sockets.  You can then 
wake up (trigger) the thread with the asyncore.loop in it by writing
to the one of the connected sockets.

Hth,
Giles Brown




More information about the Python-list mailing list