I want to call a multiprocessing.pool.map inside a process.
When initialized inside the run() function, it works. When initialized at instantiation, it does not.
I cannot figure the reason for this behavior ? What happens in the process ? I am on python 3.6
from multiprocessing import Pool, Process, Queue def DummyPrinter(key): print(key) class Consumer(Process): def __init__(self, task_queue): Process.__init__(self) self.task_queue = task_queue self.p = Pool(1) def run(self): p = Pool(8) while True: next_task = self.task_queue.get() if next_task is None: break p.map(DummyPrinter, next_task) # Works #self.p.map(DummyPrinter, next_task) # Does not Work return if __name__ == '__main__': task_queue = Queue() Consumer(task_queue).start() task_queue.put(range(5)) task_queue.put(None)