How to kill a SocketServer?

Skip Montanaro skip at pobox.com
Sun May 1 21:27:16 EDT 2005


    Paul> Yes, this is precisely what I'm asking.  How do you get the server
    Paul> to go away without going out of your way to connect to it again?
    Paul> Don't you notice if it stays around?

    Skip> It fields lots of requests, so it's possible that another request
    Skip> arrives after I exit, but I don't think that's the case.  I'll try
    Skip> to take a look in isolation when I have a moment.

Here's what I do:

    def serve_forever(self):
        while self.serving:
            r,w,e = select.select([self.socket], [], [], self.pause)
            if r:
                self.handle_request()

and set self.pause to something short-ish.  The select call times out and
the server exits.  Sorry I failed to remember that.  It's been several years
since I modified this code.

Skip




More information about the Python-list mailing list