This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: reap_children should not use WNOHANG
Type: behavior Stage: patch review
Components: Tests Versions: Python 3.1, Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: nnorwitz, pitrou, rosslagerwall
Priority: normal Keywords:

Created on 2011-03-20 16:47 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg131510 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-03-20 16:47
Using WNOHANG means that still-running children won't get collected. This seems to defeat the point of reap_children(). This patch seems to work:


diff -r adbdb3e74461 Lib/test/support.py
--- a/Lib/test/support.py       Sun Mar 20 17:36:26 2011 +0100
+++ b/Lib/test/support.py       Sun Mar 20 17:45:35 2011 +0100
@@ -1294,10 +1294,9 @@ def reap_children():
         while True:
             try:
                 # This will raise an exception on Windows.  That's ok.
-                pid, status = os.waitpid(any_process, os.WNOHANG)
-                if pid == 0:
-                    break
-            except:
+                pid, status = os.waitpid(any_process, 0)
+            except OSError:
+                # Either we're on Windows, or no running child remains.
                 break
 
 @contextlib.contextmanager
msg131512 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) Date: 2011-03-20 16:57
I'm not sure. Was reap_children() meant to just reap zombie processes or wait for all children to finish?

It seems like it was written to just reap zombie processes. Might this not cause hangs during testing sometimes if a subprocess that was started has itself hung?
msg131513 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-03-20 16:59
> I'm not sure. Was reap_children() meant to just reap zombie processes
> or wait for all children to finish?

Apparently just to reap zombie processes. At least that was the initial
intent. And it's true that we don't really need to collect all children
immediately, so perhaps this patch is overkill.

> It seems like it was written to just reap zombie processes. Might this
> not cause hangs during testing sometimes if a subprocess that was
> started has itself hung?

Yep.
msg131560 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-03-20 22:49
Probably a bad idea on my part :)
History
Date User Action Args
2022-04-11 14:57:15adminsetgithub: 55825
2011-03-20 22:49:09pitrousetstatus: open -> closed

messages: + msg131560
resolution: rejected
nosy: nnorwitz, pitrou, rosslagerwall
2011-03-20 16:59:45pitrousetnosy: nnorwitz, pitrou, rosslagerwall
messages: + msg131513
2011-03-20 16:57:55rosslagerwallsetnosy: nnorwitz, pitrou, rosslagerwall
messages: + msg131512
2011-03-20 16:47:58pitroucreate