why is there now execption for windows? trying to listen twice to the same port
Irmen de Jong
irmen.NOSPAM at xs4all.nl
Sat Mar 20 10:17:50 EDT 2010
On 20-3-2010 14:38, News123 wrote:
> I'm having a small multiprocessing manager:
>
> # ##########################
> import socket,sys
> from multiprocessing.managers import BaseManager
>
> mngr = BaseManager(address=('127.0.0.1',8089),authkey='verysecret')
> try:
> srvr = mngr.get_server()
> except socket.error as e:
> print "probably address already in use"
> sys.exit()
> print "serving"
> srvr.serve_forever()
>
>
> Under linux this script can only be run once.
> The second call will raise an exception, as the previous program is
> already listening to pot 8089.
>
>
> Under Windows however the program can be started twice.
> and will print twice "serving". This surprises me
My guess is that somewhere in the multiprocessing package the SO_REUSEADDR option is
used on the socket. And that option has different semantics on Windows than it has on
other operating systems. At least one of them being the possibility of multiple bindings
on the same port without getting an error.
See http://bugs.python.org/issue2550.
Also see the code comments to bind_port in Lib/test/test_support.py, that suggests using
SO_EXCLUSIVEADDRUSE instead under Windows, but that is not much use to you unless you
monkeypatch the multiprocessing package code.
Hope this helps
-irmen
More information about the Python-list
mailing list