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


Groups > comp.lang.python > #22249 > unrolled thread

Re: Slow termination of process

Started byRoland Hedberg <roland@catalogix.se>
First post2012-03-27 16:52 +0200
Last post2012-03-27 16:52 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Slow termination of process Roland Hedberg <roland@catalogix.se> - 2012-03-27 16:52 +0200

#22249 — Re: Slow termination of process

FromRoland Hedberg <roland@catalogix.se>
Date2012-03-27 16:52 +0200
SubjectRe: Slow termination of process
Message-ID<mailman.1043.1332859952.3037.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web