Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #22249
| 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 | <roland@catalogix.se> |
| 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 <roland@catalogix.se> |
| In-Reply-To | <CAPTjJmrnEgG5OvOWpFcZwrUOK39qrpvd1J5_9dMMFK+88QU1-A@mail.gmail.com> |
| Date | Tue, 27 Mar 2012 16:52:23 +0200 |
| Content-Transfer-Encoding | quoted-printable |
| References | <F2060B24-D02C-4FDE-A83E-8447AD8E563A@catalogix.se> <CAPTjJmrnEgG5OvOWpFcZwrUOK39qrpvd1J5_9dMMFK+88QU1-A@mail.gmail.com> |
| 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 <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.1043.1332859952.3037.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
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,
RequestHandlerClass)
and then
httpd = 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 <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
> --
> http://mail.python.org/mailman/listinfo/python-list
Roland
-----------------------------------------------------------
With anchovies there is no common ground
-- Nero Wolfe
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Slow termination of process Roland Hedberg <roland@catalogix.se> - 2012-03-27 16:52 +0200
csiph-web