How to stop a SocketServer?

Daniel Fackrell dfackrell at DELETETHIS.linuxmail.org
Mon Jun 24 12:12:03 EDT 2002


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.

It's been a while since I looked at it, so I don't have the actual methods
fresh in my mind, but hopefully this will help.

--
Daniel Fackrell (dfackrell at linuxmail.org)
When we attempt the impossible, we can experience true growth.


"Paul Rubin" <phr-n2002b at NOSPAMnightsong.com> wrote in message
news:7xhejv9af2.fsf_-_ at ruckus.brouhaha.com...
> I want to run a simple network server based on
> SocketServer.ThreadingTCPServer.  I followed the docs
> and implemented a handler class which works fine.
> Then I instantiate the server and run the serve_forever() method.
> The server listens for connections, starts threads for them
> and handles them just like it should.
>
> Question: how do I shut down the server once it's running, besides
> doing something crude like killing the process?  I'd like to be able
> to connect to the server and enter a "shutdown" command and have the
> server gracefully exit and free the port.  I haven't been able to
> figure out how to do that.
>
> Suggestions?  Thanks.





More information about the Python-list mailing list