how to stop a server (TCPServer, for example)

Huayin Wang wang at rjka.com
Tue Aug 21 19:34:28 CEST 2001


thanks and it works!

do you think it is reasonable to patch the SocketServer.py so that
it is easier to write request handler to stop the server?

I am thinking a simple patch to BaseServer class in SocketServer.py
as follow:

1) in def __init__(), add:
   self.stop = 0

2) change serve_forever to:
   def serve_forever(self):
       while not self.stop:
           self.handle_request()

thanks you again for your help!

-----Original Message-----
From: Skip Montanaro [mailto:skip at pobox.com]
Sent: Tuesday, August 21, 2001 11:02 AM
To: wang at rjka.com
Cc: python-list at python.org
Subject: Re: how to stop a server (TCPServer, for example)



    Huayin> How to make the server clean itself up and exit?
    Huayin> Do I need to implment an exit method for the server?

That's typical.  In my serve_forever method I have (effectively)

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

My exit method simply sets self.serving to 0.

-- 
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/





More information about the Python-list mailing list