简体   繁体   中英

Multiprocessing Remote Server and Socket Errors

I'm using the multiprocessing module to create a remote queue and I'm getting a socket error: "[Errno 10061] No connection could be made because the target machine actively refused it"

My Server Code is very basic:

from multiprocessing.managers import BaseManager
import Queue
queue = Queue.Queue()
class QueueManager(BaseManager): pass
QueueManager.register('get_queue', callable=lambda:queue)
m = QueueManager(address=('127.0.0.1', 50000), authkey='test')
s = m.get_server()
s.serve_forever()

All I need my server to do is to hold a job, and just pass the let the workers query the queue and pull the jobs to process.

My client is accessing the machine as such to put a job into the queue:

import uuid
from multiprocessing.managers import BaseManager
class QueueManager(BaseManager): pass
QueueManager.register('get_queue')
m = QueueManager(address=('machine ip', 50000), authkey='test')
m.connect()
queue = m.get_queue()
queue.put(r"%s" % uuid.uuid4().get_hex())
queue.put(r%s" % uuid.uuid4().get_hex())

It call the get() to get an item in the queue.

When I try to access the remote queue, I get the following error: "[Errno 10061] No connection could be made because the target machine actively refused it" as I mentioned above. If I run the code on the same machine it works fine, but when I distribute it among many machine, the clients cannot hit the server.

I can ping the machine just fine, so my first thought was to disable the firewall. I did that an still get the socket error.

I'm using right now Windows 7 for development.

Any suggestions?

Your server code is listening on the loopback network interface 127.0.0.1. This interface is not available from external networks such as an attached ethernet interface.

If you want to access your server from any network interface, use an empty host name in your server.

m = QueueManager(address=('', 50000), authkey='test')

Looks like you are listening on the loopback address. This wont work if you are trying to contact the server from outside...

Try changing the 127.0.0.1 to the machine address in the server...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM