I have a code structure that looks like this:
Class A:
def __init__(self):
processes = []
for i in range(1000):
p = Process(target=self.RunProces
A practical work-around is to break down your class, e.g. like this:
class A:
def __init__(self, ...):
pass
def compute(self):
procs = [Process(self.run, ...) for ... in ...]
[p.start() for p in procs]
[p.join() for p in procs]
def run(self, ...):
pass
pool = A(...)
pool.compute()
When you fork a process inside __init__
, the class instance self
may not be fully initialised anyway, thus it's odd to ask a subprocess to execute self.run
, although technically, yes, it's possible.
If it's not that, then it sounds like an instance of this issue:
http://bugs.python.org/issue11240