bpo-25942: make subprocess more graceful on ^C by gpshead · Pull Request #5026 · python/cpython (original) (raw)

In Python 3.3-3.6 subprocess.call and subprocess.run would immediately
SIGKILL the child process upon receiving a SIGINT (which raises a
KeyboardInterrupt). We now give the child a small amount of time to
exit gracefully before resorting to a SIGKILL.

This is also the case for subprocess.Popen.__exit__ which would
previously block indefinitely waiting for the child to die. This was
hidden from many users by virtue of subprocess.call and subprocess.run
sending the signal immediately.

Behavior change: subprocess.Popen.__exit__ will not block indefinitely
when the exiting exception is a KeyboardInterrupt. This is done for
user friendliness as people expect their ^C to actually happen. This
could cause occasional orphaned Popen objects when not using call or
run with a child process that hasn't exited.

Internal refactoring: The Popen.wait method deals with the
KeyboardInterrupt. The existing platform specific internal
methods have been renamed to _wait() which it calls.

https://bugs.python.org/issue25942