Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running multiple processes in parallel

Tags:

python

I am trying to run 2 things in parallel with multiprocessing, I have this code:

from multiprocessing import Process

def secondProcess():
    x = 0
    while True:
        x += 1

if __name__ == '__main__':
    p = Process(target=secondProcess())
    p.start()

    print "blah"

    p.join()

What seems to happen is that the second process starts running but it does not proceed with running the parent process, it just hangs until the second process finishes (so in this case never). So "blah" is never printed.

How can I make it run both in parallel?

like image 503
user350325 Avatar asked Jan 26 '26 19:01

user350325


1 Answers

You don't want to call secondProcess. You want to pass it as a parameter.

p = Process(target=secondProcess)
like image 104
Eric Urban Avatar answered Jan 28 '26 08:01

Eric Urban