how to stop a server (TCPServer, for example)

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

thanks and it works!

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

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

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

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

thanks you again for your help!

-----Original Message-----
From: Skip Montanaro [mailto:skip at]
Sent: Tuesday, August 21, 2001 11:02 AM
To: wang at
Cc: python-list at
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 =[self.socket], [], [], self.pause)
        if r:

My exit method simply sets self.serving to 0.

Skip Montanaro (skip at

More information about the Python-list mailing list