Slow termination of process

Roland Hedberg roland at
Tue Mar 27 16:52:23 CEST 2012

So, I went for the low-hanging fruit and defined my own TCPServer class

class MyTCPServer(SocketServer.TCPServer):
    def __init__(self, server_address, RequestHandlerClass):
        self.allow_reuse_address = True
        SocketServer.TCPServer.__init__(self, server_address,

and then

    httpd = MyTCPServer((hostname, port), Handler)

and this solved my problem!

So, thanks again Chris!

27 mar 2012 kl. 15:55 skrev Chris Angelico:

> On Wed, Mar 28, 2012 at 12:03 AM, Roland Hedberg <roland at> wrote:
>> When the main script is done it closes down the HTTP server by doing:
>>    op.terminate()
>> The problem I have is that if the main script is run again almost immediate then the old HTTP server
>> process doesn't seem to have released the port yet. So setting up a new server fails.
> You may wish to consider a more orderly shutdown (send the server a
> signal upon which it shuts itself down), but the simplest and most
> direct solution is to set the SO_REUSEADDR flag.
> I've not actually used the TCPServer class myself, but a cursory
> glance at the docs suggests that it's possible if you subclass it:
> Chris Angelico
> -- 


With anchovies there is no common ground 
-- Nero Wolfe

More information about the Python-list mailing list