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: Process must close the transport when the process exit
Type: Stage:
Components: asyncio Versions: Python 3.6, Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: alex.gronholm, gvanrossum, python-dev, vstinner, yselivanov
Priority: normal Keywords: patch

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

Files
File name Uploaded Description Edit
subprocess_close.patch vstinner, 2015-01-14 23:11 review
read_subprocess.py alex.gronholm, 2017-01-07 19:58
Messages (4)
msg234042 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-01-14 23:11
The asyncio.subprocess.Process class never closes the subprocess transport, whereas this transport is private.

I propose to close the transport as soon as possible: when transport.get_returncode() is called and its result is not None.

I'm not sure that it's the most efficient way to close the transport. It may be better to close the transport in the connection_lost() method of the protocol.

The patch also checks in Process.communicate() that the process is alive, and is clears the reference to the transport.
msg234070 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-01-15 12:25
New changeset df493e9c6821 by Victor Stinner in branch '3.4':
Issue #23242: asyncio.SubprocessStreamProtocol now closes the subprocess
https://hg.python.org/cpython/rev/df493e9c6821
msg234075 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-01-15 13:36
> I'm not sure that it's the most efficient way to close the transport. It may be better to close the transport in the connection_lost() method of the protocol.

"process_exited", not "connection_lost".

I implemented this option which is simpler and more efficient (always and immediatly close the transport).

Clearing the reference to the transport in the Process is less important, it can be done later in a different issue/changeset. I close this issue.
msg284930 - (view) Author: Alex Grönholm (alex.gronholm) * Date: 2017-01-07 19:58
Are you sure this has been fixed? The attached script reproduces the bug 100% reliably on my laptop.
History
Date User Action Args
2022-04-11 14:58:11adminsetgithub: 67431
2017-01-07 19:58:07alex.gronholmsetfiles: + read_subprocess.py

messages: + msg284930
2017-01-07 19:54:02alex.gronholmsetnosy: + alex.gronholm

versions: + Python 3.6
2015-01-15 13:36:57vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg234075
2015-01-15 12:25:43python-devsetnosy: + python-dev
messages: + msg234070
2015-01-14 23:11:18vstinnercreate