How to kill a SocketServer?

Peter Hansen peter at engcorp.com
Mon Apr 12 17:29:35 EDT 2004


Jean-Pierre Bergamin wrote:
> The accept() call still won't get interrupted. :-(
> 
> Other ideas?

You have three choices.

1. Run your server as a separate process, communicating with it
via some kind of RPC, and just kill it when desired.

2. Use non-blocking sockets.  This is the standard and
simplest approach in many ways.

3. Arrange to have one thread open a socket connection to the
application, waking up your accept()ing thread.  Then check
a flag which tells the server thread to exit.

By definition, blocking calls block, and you can't safely kill
a thread in Python so pick one from the above and run with it...

-Peter



More information about the Python-list mailing list