How to kill a SocketServer?

Peter Hansen peter at engcorp.com
Mon Apr 12 18:49:57 EDT 2004


Julian Smith wrote:

> Peter Hansen <peter at engcorp.com> wrote:
>>Jean-Pierre Bergamin wrote:
>>>The accept() call still won't get interrupted. :-(
>>You have three choices.
>>
[snip]
> 
> I have a class that can be constructed from a socket and looks like a file
> object, but whose blocking read() method can be interrupted by a different
> thread. The read() method uses poll() to block on both the real underlying
> file descriptor and an internal file descriptor created using os.pipe().
> 
> It works on OpenBSD and Cygwin, but I haven't tried it on anything else yet.
> I'm a relative newcomer to Python, so I'm sure there are some subleties that
> I've missed.
> 
> See http://www.op59.net/cancelable.py if you're interested.

Looks interesting.  I guess I should have qualified my answer
by saying something like "platform-specific code might allow for
other solutions". :-)  I'm pretty sure cancelable.py's solution
wouldn't work on Windows (but if I'm wrong, then of course:
"amongst our choices are separate process, non-blocking socket,
connection from another thread, and cancelable.py, and of course
an almost fanatical devotion to the Pope...")  ;-)

-Peter



More information about the Python-list mailing list