socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use')

Laszlo Nagy gandalf at shopzeus.com
Sun Feb 1 02:37:13 EST 2009


> 8<------------------------------
>
>   
>> .......  Setting the
>> SO_REUSEADDR flag on POSIX fixes this problem (don't set it on Windows,
>> though).
>>     
>
> Why not?  I have been merrily setting it, and I have not noticed anything weird.
> (yet)
>   
Please see my original post. I specifically stated that I do not want to 
use setsockopt and be able to listen on the same port from many 
processes. I knew that I could use SO_REUSEADDR, but I'm heistating to 
do so. I must guarantee that only one process listens on a given port at 
the same time.

Maybe I could use some kind of locking, but it would be too difficult:

- mutexes are great but they are platform dependent and they are not in 
the standard lib
- the listening processes do not see each other's home directory so file 
locking cannot be used for this
- these processes will probably listen on many ports at the same time, 
it is also a problem with mutexes/file locks (who wants 50 lock files to 
be created?)


 Best,

   Laszlo





More information about the Python-list mailing list