I am following an instruction from youtube to learn multiprocessing
from multiprocessing import Pool
import subprocess
import time
def f(n): sum = 0 for x in range(1000): sum += x*x return sum
if __name__ == "__main__": t1 = time.time() p = Pool() result = p.map(f, range(10000)) p.close() p.join() print("Pool took: ", time.time()-t1)I am puzzled about p.close() and p.join()
when processes were closed, they did not exist any more, how could manipulate .join to them?
1 Answer
join() waits for a child process to be killed. Killed processes send a signal informing their parents that they are quite dead. close() doesn't kill any process, It just closes a pipe which informs readers of that pipe, that there will be no more data coming through it.