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


Groups > comp.lang.python > #22246

Re: Slow termination of process

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.080
X-Spam-Evidence '*H*': 0.84; '*S*': 0.00; 'yet.': 0.05; 'subject:process': 0.09; 'closes': 0.16; 'doing:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'shutdown': 0.16; 'subclass': 0.16; 'received:209.85.210.174': 0.20; 'received:mail-iy0-f174.google.com': 0.20; 'wrote:': 0.21; 'http': 0.22; 'header:In-Reply-To:1': 0.22; 'wed,': 0.24; 'run': 0.26; 'message-id:@mail.gmail.com': 0.27; "i've": 0.28; 'fails.': 0.29; 'class': 0.29; 'setting': 0.30; "doesn't": 0.30; 'script': 0.31; 'received:209.85': 0.32; 'received:209.85.210': 0.32; 'chris': 0.32; 'received:google.com': 0.32; 'problem': 0.34; 'url:python': 0.34; 'server': 0.34; 'received:209': 0.35; 'actually': 0.35; 'done': 0.36; 'url:library': 0.36; 'but': 0.36; 'url:org': 0.36; 'port': 0.37; 'to:addr:python-list': 0.39; 'to:addr:python.org': 0.40; 'mar': 0.61; 'most': 0.63; 'more': 0.63; '2012': 0.69; 'direct': 0.70; 'wish': 0.72; 'it:': 0.76; '12:03': 0.84; 'flag.': 0.84; 'glance': 0.84; 'suggests': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=W4hR9WurgOQP1L4ki3yMFxs9E6cIEJmGPe8w8gTbwAA=; b=LGovWPdP1t6hFXksVCp8zbwcwtewvFS/j+vy6DVI5GKW6JBwULzDaYb3I4KGBVaD/M Yj866VwFlJXbN+0qbiF0GRBCRR2swYzr92GcEpDW8SjZ0WVHtHEArQE6svDBb2PqNOp2 UrDF3rEgrzV10wYdViwmIjkSdbCGyGtvb2+0Qd+0m5eVpvpQWlhpxizM1W6auMXMW+1+ ptdsvN+r2dzrT+XkS8Wh70o4UxaGphKQTn47uqVSksY2hu/k/uPZoAI1PWPUWQFX8OCX BAtLBVdclRD/vBZymYcXZ8S38AX99TWa593BJigEIdHqptbGXTVhxUCyVEnmB3aJcIXr z1mA==
MIME-Version 1.0
In-Reply-To <F2060B24-D02C-4FDE-A83E-8447AD8E563A@catalogix.se>
References <F2060B24-D02C-4FDE-A83E-8447AD8E563A@catalogix.se>
Date Wed, 28 Mar 2012 00:55:48 +1100
Subject Re: Slow termination of process
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1040.1332856552.3037.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1332856552 news.xs4all.nl 6972 [2001:888:2000:d::a6]:40946
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:22246

Show key headers only | 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