Reputation: 1620
I'm currently experimenting with multiprocessing in Python, and I've made this small script:
import multiprocessing, time
def test_def():
time.sleep(5)
p = multiprocessing.Process(target=test_def())
print p, p.is_alive()
Yet, when I run it, it waits 5 secondes before it prints out:
<Process(Process-1, initial)> False
To me, this makes little sense. If p.start() isn't called, then how can the function be running?
Upvotes: 0
Views: 64
Reputation: 21851
The target=
keyword expects a function to be called in the new process.
You are effectively passing it None
since you have written target=test_def()
and not target=test_def
. The former gives the return value of your test_def()
function after calling it (which is None
).
You are also never actually starting your process, so you need to add a p.start()
and p.join()
as well.
Upvotes: 1