p.close and p.join in multiporcessing.Pool

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like