'Address already in use' ... with TCPServer

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Jan 30 13:44:22 CET 2009


En Fri, 30 Jan 2009 10:16:42 -0200, Giampaolo Rodola' <gnewsg at gmail.com>  
escribió:
> On 30 Gen, 10:16, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
>> En Fri, 30 Jan 2009 05:43:33 -0200, Mabooka-Mabooka Mbe-Mbe  
>> <ochichinyezaboom... at yahoo.com> escribió:
>>
>> >   setsockopt(REUSEADDR)...
>>
>> >>>> s.allow_reuse_address=1
>> > should do the trick.
>>
>> It's too late then; bind() has already been called. The easiest way is  
>> to define your own derived class:
>>
>> import SocketServer
>>
>> class TCPServer(SocketServer.TCPServer):
>>      allow_reuse_address = True
>>
>> s = TCPServer(...)
>
> What's even faster is setting the class attribute right after the
> module import:
>
>>>> import SocketServer
>>>> SocketServer.TCPServer.allow_reuse_address = True

...but potentially unsafe if the application uses other servers in other  
places. C'mon, defining the new class can be a one-liner also, why take  
the risk?

-- 
Gabriel Genellina




More information about the Python-list mailing list