Why can't I return a ServerProxy object from a function executed by a pool of processes?
This works:
def function():
server=initserver()
def initserver():
serv=xmlrpclib.ServerProxy("http://server:6060/RPC2")
return serv
However, this does not:
def function():
pool = Pool (processes=4)
results=[pool.apply(initserver, args=()) for i in range (0, 4)
pool.close()
pool.join()
def initserver():
serv=xmlrpclib.ServerProxy("http://server:6060/RPC2")
return serv
I know that I have to "get" the values from "results", but I just don't have the chance. In the moment that the "return serv" is executed, the program stops with the following output (one block of these for each process of the pool) and I have to kill it manually:
Process PoolWorker-4:
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python2.7/multiprocessing/pool.py", line 99, in worker
put((job, i, result))
File "/usr/lib/python2.7/multiprocessing/queues.py", line 390, in put
return send(obj)
File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python2.7/xmlrpclib.py", line 1578, in __request
verbose=self.__verbose
File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python2.7/xmlrpclib.py", line 1297, in single_request
return self.parse_response(response)
File "/usr/lib/python2.7/xmlrpclib.py", line 1473, in parse_response
return u.close()
File "/usr/lib/python2.7/xmlrpclib.py", line 793, in close
raise Fault(**self._stack[0])
Fault: <Fault -506: "Method '__getinitargs__' not defined">
¿Ideas?
I could make a global variable "serv" for each process (in fact that is how I am dealing with this), but that has this other issue:
Concurrent XMLRPC-C calls with global ServerProxy object not working as expected