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

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

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest