I have to do CPU-bound tasks, every task is assigened to a process with multiprocessing.Pool
with multiprocessing.Pool(3) as p:
results = list(p.map(task, [args1, args2, args3, aegs4, ..., argsn]))
In every task there is a for loop, as the last one, that can be parallelized with multiprocessing.pool, but when i do it I get:
AssertionError: daemonic processes are not allowed to have children
I know one possible solution is: Python Process Pool non-daemonic? But my question is: should I make a pool process non-deamon or it is unsafe?
Now I do this:
# subtask
def update(args):
...
return updated_a
# task
def task(args):
...
for i in range(200):
# evaluations
...
with multiprocessing.get_context('spawn').Pool(len(self.arraies)) as p:
self.arraies = list(p.map(update, [[..., a] for a in self.arraies]))
...
return result
...
ss = np.random.SeedSequence()
tasks_seeds = ss.spawn(N_ITERATIONS + 1)
streams = [np.random.default_rng(s) for s in tasks_seeds]
results = []
with multiprocessing.get_context('spawn').Pool(3) as p:
results = list(p.map(task, [[...,streams[i]] for i in range(N_ITERATIONS)]))
...