classification
Title: subprocess.poll() does not handle errno.ECHILD "No child processes"
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.4, Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: gregory.p.smith, jcea, python-dev, tshepang, twhitema
Priority: normal Keywords: patch

Created on 2012-08-21 19:15 by twhitema, last changed 2012-09-29 19:03 by gregory.p.smith. This issue is now closed.

Files
File name Uploaded Description Edit
issue15756_poll_v1.patch twhitema, 2012-08-21 19:20 review
Messages (5)
msg168798 - (view) Author: Todd Whiteman (twhitema) Date: 2012-08-21 19:15
In the case of a "errno.ECHILD" exception - Python's subprocess module misses the fact that the process has already ended.

The following code will wait indefinitely, even though the launched process is quickly ended:

import subprocess, signal
signal.signal(signal.SIGCLD, signal.SIG_IGN)
p = subprocess.Popen(['echo','foo'])
while p.poll() is None:
   pass # wait for the process to exit

Note: This is the exact same issue as issue1731717, but applying to the subprocess.poll() method instead of the subprocess.wait() method.
msg168799 - (view) Author: Todd Whiteman (twhitema) Date: 2012-08-21 19:20
The attached patch handles errno.ECHILD in the _internal_poll() method and I've updated the existing "sigchild_ignore.py" test file to perform polling as well.

An unpatched version of Pyhton would normally hang on this particular test, whilst the patched version will run successfully.
msg169581 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2012-08-31 20:38
thanks!  I'll take care of getting this fix in.
msg171588 - (view) Author: Roundup Robot (python-dev) Date: 2012-09-29 18:58
New changeset 484c50bf445c by Gregory P. Smith in branch '3.2':
Fixes issue #15756: subprocess.poll() now properly handles errno.ECHILD
http://hg.python.org/cpython/rev/484c50bf445c

New changeset ba8d85552e34 by Gregory P. Smith in branch '3.3':
Fixes issue #15756: subprocess.poll() now properly handles errno.ECHILD
http://hg.python.org/cpython/rev/ba8d85552e34

New changeset 9032b3f52819 by Gregory P. Smith in branch 'default':
Fixes issue #15756: subprocess.poll() now properly handles errno.ECHILD to
http://hg.python.org/cpython/rev/9032b3f52819
msg171589 - (view) Author: Roundup Robot (python-dev) Date: 2012-09-29 19:03
New changeset 53e91fa35f8e by Gregory P. Smith in branch '2.7':
Issue #15756: subprocess.poll() now properly handles errno.ECHILD to
http://hg.python.org/cpython/rev/53e91fa35f8e
History
Date User Action Args
2012-09-29 19:03:53gregory.p.smithsetstatus: open -> closed
resolution: fixed
2012-09-29 19:03:25python-devsetmessages: + msg171589
2012-09-29 18:58:44python-devsetnosy: + python-dev
messages: + msg171588
2012-09-10 02:12:51jceasetnosy: + jcea
2012-08-31 20:38:34gregory.p.smithsetassignee: gregory.p.smith
messages: + msg169581
2012-08-31 19:31:00berker.peksagsetversions: - Python 2.6, Python 3.1
2012-08-25 08:49:05tshepangsetnosy: + tshepang
2012-08-21 19:20:36twhitemasetfiles: + issue15756_poll_v1.patch
keywords: + patch
messages: + msg168799
2012-08-21 19:15:33twhitemasetnosy: + gregory.p.smith
2012-08-21 19:15:17twhitemacreate