Path: csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.112 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.78; '*S*': 0.00; 'yet.': 0.05; 'subject:process': 0.09; 'closes': 0.16; 'doing:': 0.16; 'fruit': 0.16; 'handler)': 0.16; 'port),': 0.16; 'problem!': 0.16; 'shutdown': 0.16; 'subclass': 0.16; 'def': 0.20; 'wrote:': 0.21; 'http': 0.22; 'header:In-Reply-To:1': 0.22; 'skip:m 30': 0.24; 'wed,': 0.24; 'run': 0.26; 'defined': 0.27; "i've": 0.28; 'fails.': 0.29; 'class': 0.29; 'setting': 0.30; 'went': 0.30; "doesn't": 0.30; 'script': 0.31; 'url:mailman': 0.31; 'chris': 0.32; 'problem': 0.34; 'thanks': 0.34; 'skip:s 20': 0.34; 'skip:s 30': 0.34; 'url:python': 0.34; 'server': 0.34; 'there': 0.35; 'skip:_ 10': 0.35; 'actually': 0.35; 'url:listinfo': 0.36; 'done': 0.36; 'url:library': 0.36; 'but': 0.36; 'url:org': 0.36; 'port': 0.37; 'so,': 0.37; 'common': 0.38; 'received:org': 0.38; 'to:addr :python-list': 0.39; 'to:addr:python.org': 0.40; 'mar': 0.61; 'most': 0.63; 'more': 0.63; 'header:Message-Id:1': 0.65; '2012': 0.69; 'direct': 0.70; 'wish': 0.72; 'received:130': 0.73; 'it:': 0.76; '12:03': 0.84; '15:55': 0.84; 'flag.': 0.84; 'glance': 0.84; 'solved': 0.84; 'suggests': 0.84 X-Virus-Scanned: amavisd-new at catalogix.se Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Apple Message framework v1257) Subject: Re: Slow termination of process From: Roland Hedberg In-Reply-To: Date: Tue, 27 Mar 2012 16:52:23 +0200 Content-Transfer-Encoding: quoted-printable References: To: python-list@python.org X-Mailer: Apple Mail (2.1257) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332859952 news.xs4all.nl 6927 [2001:888:2000:d::a6]:58765 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22249 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 =3D True SocketServer.TCPServer.__init__(self, server_address, RequestHandlerClass) and then httpd =3D MyTCPServer((hostname, port), Handler) httpd.serve_forever() 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 = wrote: >> When the main script is done it closes down the HTTP server by doing: >>=20 >> op.terminate() >>=20 >> 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. >=20 > 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. >=20 > http://docs.python.org/library/socket.html?highlight=3Dso_reuseaddr >=20 > 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: >=20 > = http://docs.python.org/library/socketserver.html#SocketServer.BaseServer.a= llow_reuse_address >=20 > Chris Angelico > --=20 > http://mail.python.org/mailman/listinfo/python-list Roland ----------------------------------------------------------- With anchovies there is no common ground=20 -- Nero Wolfe