Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #22246

Re: Slow termination of process

References <F2060B24-D02C-4FDE-A83E-8447AD8E563A@catalogix.se>
Date 2012-03-28 00:55 +1100
Subject Re: Slow termination of process
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1040.1332856552.3037.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Mar 28, 2012 at 12:03 AM, Roland Hedberg <roland@catalogix.se> 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.

http://docs.python.org/library/socket.html?highlight=so_reuseaddr

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:

http://docs.python.org/library/socketserver.html#SocketServer.BaseServer.allow_reuse_address

Chris Angelico

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Slow termination of process Chris Angelico <rosuav@gmail.com> - 2012-03-28 00:55 +1100

csiph-web