New submission from Martin Richard:

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.

----------
components: asyncio
files: add-detach-to-subprocess_transport.patch
keywords: patch
messages: 236808
nosy: gvanrossum, haypo, martius, yselivanov
priority: normal
severity: normal
status: open
title: Proposal for asyncio: SubprocessTransport.detach() to detach a process 
from a transport
type: enhancement
versions: Python 3.3, Python 3.4, Python 3.5
Added file: 
http://bugs.python.org/file38263/add-detach-to-subprocess_transport.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23540>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to