multiprocessing BaseManager doesn't clean up net connections?

Chris Brooks cab938 at mail.usask.ca
Thu Jan 1 03:01:50 CET 2009


Hi,

I'm trying to use remote managers in the multiprocessing module to listen
for some events synchronously while my program goes off and does other
things.  I use the .start() method which forks a new process to handle
communication.  When I catch the sigint and call sys.exit() though, the
network port is still bound even after the python interpretor finishes. 
Here is my short code and the output:

from multiprocessing.managers import BaseManager
import threading
import sys
import signal
import time

class WorkManager(BaseManager):
    def __init__(self):
        BaseManager.__init__(self,address=('', 51114), authkey='chris')
        self.register('get_string', callable=self.getString)
        
    def getString(self):
        return "hi"

manager = WorkManager()
manager.start()

def quit( arg1, arg2 ):
    sys.exit()
    
signal.signal(signal.SIGINT, quit)

#busy wait
while 1:
    time.sleep(1)



cab938 at ubuntu:~$ python2.6 server.py 
^Ccab938 at ubuntu:~$ python2.6 server.py 
Process WorkManager-1:
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/multiprocessing/process.py", line 231, in
_bootstrap
    self.run()
  File "/usr/local/lib/python2.6/multiprocessing/process.py", line 88, in
run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python2.6/multiprocessing/managers.py", line 517, in
_run_server
    server = cls._Server(registry, address, authkey, serializer)
  File "/usr/local/lib/python2.6/multiprocessing/managers.py", line 136, in
__init__
    self.listener = Listener(address=address, backlog=5)
  File "/usr/local/lib/python2.6/multiprocessing/connection.py", line 97, in
__init__
    self._listener = SocketListener(address, family, backlog)
  File "/usr/local/lib/python2.6/multiprocessing/connection.py", line 217,
in __init__
    self._socket.bind(address)
  File "<string>", line 1, in bind
error: [Errno 98] Address already in use
Traceback (most recent call last):
  File "server.py", line 16, in <module>
    manager.start()
  File "/usr/local/lib/python2.6/multiprocessing/managers.py", line 499, in
start
    self._address = reader.recv()
EOFError
cab938 at ubuntu:~$ 


Comments?  Is this a bug, or is there a better way to clean up the manager
myself before shutting down?

Chris
-- 
View this message in context: http://www.nabble.com/multiprocessing-BaseManager-doesn%27t-clean-up-net-connections--tp21238615p21238615.html
Sent from the Python - python-list mailing list archive at Nabble.com.




More information about the Python-list mailing list