I am subclassing the Process class, into a class I call EdgeRenderer. I want to use multiprocessing.Pool
, except instead of regular Processes, I want them to be instances of my EdgeRenderer. Possible? How?
From Jesse Noller:
It is not currently supported in the API, but would not be a bad addition. I'll look at adding it to python2.7/2.6.3 3.1 this week
This seems to work:
import multiprocessing as mp
ctx = mp.get_context() # get the default context
class MyProcess(ctx.Process):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
print("Hi, I'm custom a process")
ctx.Process = MyProcess # override the context's Process
def worker(x):
print(x**2)
p = ctx.Pool(4)
nums = range(10)
p.map(worker, nums)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With