classification
Title: child process disappears when removing a print statement after its creation
Type: behavior Stage: resolved
Components: Versions: Python 3.7, Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: calimeroteknik, davin, giampaolo.rodola, gregory.p.smith, pitrou
Priority: normal Keywords:

Created on 2018-09-26 16:42 by calimeroteknik, last changed 2018-09-26 17:24 by pitrou. This issue is now closed.

Files
File name Uploaded Description Edit
hang.py calimeroteknik, 2018-09-26 16:42 Make cpython hang or not on waitpid by insterting a print or sleep statement
except-out.py calimeroteknik, 2018-09-26 16:43 Make cpython forget a child process or not by inserting a print or sleep statement
Messages (5)
msg326485 - (view) Author: calimeroteknik (calimeroteknik) Date: 2018-09-26 16:42
When two processes are created and killed, the behaviour is different if print or sleep statements are inserted.
It can also be random (different results executing the same program several times) on certain machines and versions of python.

Attached two versions, one where the child process mysteriously disappears in the cpython interpreter, and another other one that raises ChildProcessError: [Errno 10] No child processes.

This shows up with cpython, all versions I tested (3.7, 3.6, 3.5, 2.7). pypy is unaffected.
msg326488 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2018-09-26 17:01
I don't think hang.py is correct.  If you launch a process using subprocess, the subprocess owns the child process.  You should not call waitpid() or os.kill() separately.  Also, since you don't keep a reference to the subprocess.Popen object, its destructor will run and may call waitpid() on the child process.  Depending on when exactly the destructor runs, it can interfere with your own waitpid() call.
msg326489 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2018-09-26 17:01
Those remarks apply to except-out.py, as well.
msg326493 - (view) Author: calimeroteknik (calimeroteknik) Date: 2018-09-26 17:13
So this is invalid library usage, we need to run .wait() on the Popen object.
msg326496 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2018-09-26 17:24
Indeed!
History
Date User Action Args
2018-09-26 17:24:18pitrousetmessages: + msg326496
2018-09-26 17:13:17calimerotekniksetstatus: open -> closed
resolution: not a bug
messages: + msg326493

stage: resolved
2018-09-26 17:01:55pitrousetmessages: + msg326489
2018-09-26 17:01:17pitrousetnosy: + gregory.p.smith, giampaolo.rodola
messages: + msg326488
2018-09-26 16:43:09calimerotekniksetfiles: + except-out.py
2018-09-26 16:42:21calimeroteknikcreate