I am trying to use the multiprocessing package within an rpyc
service, but get ValueError: pickling is disabled
when I try to call the exposed function from the client. I understand that the multiprocesing
package uses pickling to pass information between processes and that pickling is not allowed in rpyc
because it is an insecure protocol. So I am unsure what the best way (or if there is anyway) to use multiprocessing with rpyc. How can I make use of multiprocessing within a rpyc service? Here is the server side code:
import rpyc
from multiprocessing import Pool
class MyService(rpyc.Service):
def exposed_RemotePool(self, function, arglist):
pool = Pool(processes = 8)
result = pool.map(function, arglist)
pool.close()
return result
if __name__ == "__main__":
from rpyc.utils.server import ThreadedServer
t = ThreadedServer(MyService, port = 18861)
t.start()
And here is the client side code that produces the error:
import rpyc
def square(x):
return x*x
c = rpyc.connect("localhost", 18861)
result = c.root.exposed_RemotePool(square, [1,2,3,4])
print(result)
allow_pickle=True
. – Discerning