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: asyncio: kill the subprocess if the creation failed
Type: Stage:
Components: asyncio Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, python-dev, vstinner, yselivanov
Priority: normal Keywords: patch

Created on 2015-01-06 00:00 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
asyncio_subprocess_kill.patch vstinner, 2015-01-06 00:00 review
Messages (2)
msg233486 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-01-06 00:00
The creation of a subprocess in asyncio is complex, it is composed of multiple steps (callbacks scheduled by call_soon, coroutines, etc.). The creation can fail because of different reasons. I guess that the most common reason is a cancellation of a task, explicitly or because of a timeout (asyncio.wait_for).

I propose to ensure that everything is cleaned up on failure, especially to kill the subprocess. This choice comes from the subprocess module, it kills the subprocess on error.

Attached patch implements this change. It also fixes a bug noticed in the issue #23140: a call to waiter.set_result() in SubprocessStreamProtocol.connection_made() is not protected by a test on the future state.

When I wrote the unit tests, I tried to mock subprocess.Popen to ensure that the Popen.kill() method is called, but mocking a subprocess for asyncio is complex. I chose to keep the test simple.
msg233984 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-01-14 01:15
New changeset 1eae3b6fbec6 by Victor Stinner in branch '3.4':
Python issue #23173: sync with Tulip
https://hg.python.org/cpython/rev/1eae3b6fbec6
History
Date User Action Args
2022-04-11 14:58:11adminsetgithub: 67362
2015-01-14 01:15:17vstinnersetstatus: open -> closed
resolution: fixed
2015-01-14 01:15:01python-devsetnosy: + python-dev
messages: + msg233984
2015-01-06 00:00:45vstinnercreate