[issue25960] Popen.wait() hangs with SIGINT when os.waitpid() does not
Chris Jerdonek
report at bugs.python.org
Sun Dec 27 05:58:02 EST 2015
New submission from Chris Jerdonek:
I came across a situation where Popen.wait() hangs and os.waitpid() doesn't hang. It seems like a bug, but I don't know for sure. This is with Python 3.5.1.
To reproduce, save the following to demo.py:
import os, signal, subprocess
class State:
process = None
def handle_signal(signalnum, frame):
print("Handling: {0}".format(signalnum))
p = State.process
# The following line hangs:
p.wait()
# However, this line does not hang:
# os.waitpid(p.pid, 1)
print("Done waiting")
signal.signal(signal.SIGINT, handle_signal)
p = subprocess.Popen("while true; do echo sleeping; sleep 2; done",
shell=True)
State.process = p
p.wait()
Then run the following, hit Control-C, and it will hang:
$ python demo.py
sleeping
sleeping
^CHandling: 2
It will still hang if you insert "p.terminate()" right before p.wait().
However, calling "os.waitpid(p.pid, ...)" instead of p.wait() exits immediately and does not hang. The behavior also occurs without shell=True.
----------
components: Library (Lib)
messages: 257071
nosy: chris.jerdonek
priority: normal
severity: normal
status: open
title: Popen.wait() hangs with SIGINT when os.waitpid() does not
type: behavior
versions: Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25960>
_______________________________________
More information about the Python-bugs-list
mailing list