[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

why is there now execption for windows? trying to listen twice to the same port

News123

3/20/2010 1:39:00 PM

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

Howver only one of them will successfully listen and respond to
connections, but I don't get an exception.

Is this to be expected?

I'd like to be sure, that the manager is only started once and that it
can be started anytime it's not up.


N
4 Answers

Irmen de Jong

3/20/2010 2:18:00 PM

0

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....
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

News123

3/20/2010 2:52:00 PM

0

Hi Irmen,


Irmen de Jong wrote:
> 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 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....
> 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.
>

Yes this might be.


Then I think, that I should report it either as bug / enhancement
request. However I am not at all aware of the issue reporting process
concerning python. (special site / module developer, PEP . . . )

For the short term:
I wonder now how to solve my problem that only one manager is started
and the second one should just aborts.

Some days ago I started a discussion in the thread
"how to start a python script only once".
I hoped, that the listening socket of the manager would just take care
of the issue.

N







Terry Reedy

3/20/2010 4:33:00 PM

0

On 3/20/2010 10:52 AM, News123 wrote:
> Hi Irmen,
>
>
> Irmen de Jong wrote:
>> 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 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....
>> 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.
>>
>
> Yes this might be.
>
>
> Then I think, that I should report it either as bug / enhancement

I agree. I would guess that the difference is not intentional.

> request. However I am not at all aware of the issue reporting process
> concerning python. (special site / module developer, PEP . . . )

bugs.python.org

Terry Jan Reedy

News123

3/20/2010 5:11:00 PM

0

Terry Reedy wrote:
> On 3/20/2010 10:52 AM, News123 wrote:
>> Hi Irmen,
>>
>>
>> Irmen de Jong wrote:
>>> 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 Windows however the program can be started twice.
>>>> and will print twice "serving". This surprises me
>>>
.. . .
>>
>> Then I think, that I should report it either as bug / enhancement
>
> I agree. I would guess that the difference is not intentional.
>
>> request. However I am not at all aware of the issue reporting process
>> concerning python. (special site / module developer, PEP . . . )
>
> bugs.python.org
>
Thanks,


I created an account and submitted the issue


N