How to kill a SocketServer?

Andrew Dalke dalke at dalkescientific.com
Sun May 1 04:06:39 EDT 2005


Paul Rubin wrote:
> Let's say you have a SocketServer with the threading mix-in and you
> run serve_forever on it.  How can you shut it down, or rather, how can
> it even shut itself down? 

I looked at CherryPy's server because I know it uses Python's
BaseHTTPServer which is derived from SocketServer, and I know
it's multithreaded.

Turns out I don't know enough about it to make a reasonable
summary, unless I do a lot more research.  Here's some text
from _cphttpserver

  class PooledThreadServer(SocketServer.TCPServer):

    allow_reuse_address = 1

    """A TCP Server using a pool of worker threads. This is superior to the
       alternatives provided by the Python standard library, which only offer
       (1) handling a single request at a time, (2) handling each request in
       a separate thread (via ThreadingMixIn), or (3) handling each request in
       a separate process (via ForkingMixIn). It's also superior in some ways
       to the pure async approach used by Twisted because it allows a more
       straightforward and simple programming model in the face of blocking
       requests (i.e. you don't have to bother with Deferreds).""" 

which means it went a different route.  Looks like a
request comes in and is put to a work queue.  Clients get
from it.  There's a special work queue item to tell
the threads to stop.

				Andrew
				dalke at dalkescientific.com




More information about the Python-list mailing list