How to stop a SocketServer?

Peter Hansen peter at engcorp.com
Mon Jun 24 13:33:19 EDT 2002


Daniel Fackrell wrote:
> 
> I faced this problem with a simple chat server I wrote.  I expected that
> termination of the server with <ctrl-C> should have stopped it immediately,
> but it instead waits until some communication is received from each thread
> that was stopped at a read().
> 
> It appears that the current threading implementation does not provide for
> termination of threads inside a single python statement (such as a
> filelike.read()), so I am considering a move to character I/O, checking to
> verify that a character is available before each read.

The proper solution to this kind of problem is to use timeouts
and select.  There's generally no need to check for the data
being available ahead of time by _polling_, which is inefficient.

-Peter



More information about the Python-list mailing list