Strange socket problem

Magnus Lycka lycka at carmen.se
Wed Jun 15 17:46:50 CEST 2005


huy wrote:
> Hi,
> 
> I'm using cherrypy to provide a user interface for users to start a 
> linux server program eg. os.system("nohup myserver.py &"). The problem 
> is that if I stop cherrypy server and restart, I get the "Address 
> Already In Use" problem until I stop myserver.py. Can someone shed some 
> light on why this happens ? Why would the socket be held up in the other 
> process ?

As I understand it, if a socket is closed by the server, the OS
will typically hold on to the socket for a while, in case the
client wants some packages resent etc. This might be a part of
your problem.

Andrew Dalke explained it much better to me when I ran into this
some time ago. Quoted below:

> Magnus Lyckå wrote:
>> Why doesn't my socket
>> get released by the OS when I exit via my handle_error?
> 
> Hi Magnus,
> 
>   I wrote about this at
> http://www.dalkescientific.com/writings/diary/archive/2005/04/21/using_xmlrpc.html
> 
> The reason for it is described at
>   http://hea-www.harvard.edu/~fine/Tech/addrinuse.html
> 
> You can set the class variable "allow_reuse_address = True" in
> your derived ExitableSocketServer to get the behaviour you
> expect, at the expense of some problems mentioned in the
> above URL.
> 
>     Andrew
>     dalke at dalkescientific.com



More information about the Python-list mailing list