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: Proposal for asyncio: SubprocessTransport.detach() to detach a process from a transport
Type: enhancement Stage:
Components: asyncio Versions: Python 3.3, Python 3.4, Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, martius, vstinner, yselivanov
Priority: normal Keywords: patch

Created on 2015-02-27 18:11 by martius, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
add-detach-to-subprocess_transport.patch martius, 2015-02-27 18:11 First try: add a detach() method to SubprocessTransport.
Messages (1)
msg236808 - (view) Author: Martin Richard (martius) * Date: 2015-02-27 18:11
I would like to add a detach() method to base_suprocess.BaseSuprocessTransport, which would release the underlying Popen object to the user, pretty much like socket.detach() detaches a socket object and returns the fd.

The rationale is the following: the lifetime of a subprocess started using a loop is bound to that loop, or require to clause the loop without terminating the process which leads to resource leaks (the stdin/stdout pipes can't be closed).

It may be useful in some cases. For instance, I create a fork of a process running a loop which started one or more subprocesses. In the child processus, I'd like to close the pipes and free the transport objects by calling:

    proc = transport.detach()
    transport.close()

    proc.stdin.close()
    proc.stdout.close()
    proc.stderr.close()


The process is still running, in the parent process, everything looks like before the fork, the child can forget about the parent loop without fearing resource leaks.

It is somewhat related to http://bugs.python.org/issue21998 (Support fork).

I propose a patch which adds BaseSubprocessTransport.detach(), a specialized version for _UnixSubprocessTransport taking care of removing the callbacks from the ChildWatcher and a detach method for the pipes transports for unix and proactor.
History
Date User Action Args
2022-04-11 14:58:13adminsetgithub: 67728
2015-02-27 18:11:10martiuscreate