👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
Learning about Python Multiprocessing (from a PMOTW article) and would love some clarification on what exactly the join()
method is doing.
In an old tutorial from 2008 it states that without the p.join()
call in the code below, "the child process will sit idle and not terminate, becoming a zombie you must manually kill".
from multiprocessing import Process
def say_hello(name="world"):
print "Hello, %s" % name
p = Process(target=say_hello)
p.start()
p.join()
I added a printout of the PID
as well as a time.sleep
to test and as far as I can tell, the process terminates on its own:
from multiprocessing import Process
import sys
import time
def say_hello(name="world"):
print "Hello, %s" % name
print "Starting:", p.name, p.pid
sys.stdout.flush()
print "Exiting :", p.name, p.pid
sys.stdout.flush()
time.sleep(20)
p = Process(target=say_hello)
p.start()
# no p.join()
within 20 seconds:
936 ttys000 0:00.05 /Library/Frameworks/Python.framework/Versions/2.7/Reso
938 ttys000 0:00.00 /Library/Frameworks/Python.framework/Versions/2.7/Reso
947 ttys001 0:00.13 -bash
after 20 seconds:
947 ttys001 0:00.13 -bash
Behavior is the same with p.join()
added back at end of the file. Python Module of the Week offers a very readable explanation of the module; "To wait until a process has completed its work and exited, use the join() method.", but it seems like at least OS X was doing that anyway.
Am also wondering about the name of the method. Is the .join()
method concatenating anything here? Is it concatenating a process with it"s end? Or does it just share a name with Python"s native .join()
method?
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from What exactly is Python multiprocessing Module”s .join() Method Doing?, check other ast Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano What exactly is Python multiprocessing Module”s .join() Method Doing?
- Deutsch What exactly is Python multiprocessing Module”s .join() Method Doing?
- Français What exactly is Python multiprocessing Module”s .join() Method Doing?
- Español What exactly is Python multiprocessing Module”s .join() Method Doing?
- Türk What exactly is Python multiprocessing Module”s .join() Method Doing?
- Русский What exactly is Python multiprocessing Module”s .join() Method Doing?
- Português What exactly is Python multiprocessing Module”s .join() Method Doing?
- Polski What exactly is Python multiprocessing Module”s .join() Method Doing?
- Nederlandse What exactly is Python multiprocessing Module”s .join() Method Doing?
- 中文 What exactly is Python multiprocessing Module”s .join() Method Doing?
- 한국어 What exactly is Python multiprocessing Module”s .join() Method Doing?
- 日本語 What exactly is Python multiprocessing Module”s .join() Method Doing?
- हिन्दी What exactly is Python multiprocessing Module”s .join() Method Doing?
Rome | 2023-03-29
Maybe there are another answers? What What exactly is Python multiprocessing Module”s .join() Method Doing? exactly means?. Checked yesterday, it works!
Shanghai | 2023-03-29
stat Python module is always a bit confusing 😭 What exactly is Python multiprocessing Module”s .join() Method Doing? is not the only problem I encountered. Will use it in my bachelor thesis
California | 2023-03-29
Maybe there are another answers? What What exactly is Python multiprocessing Module”s .join() Method Doing? exactly means?. I just hope that will not emerge anymore