Issue23540
Created on 2015年02月27日 18:11 by martius, last changed 2022年04月11日 14:58 by admin.
| 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:13 | admin | set | github: 67728 |
| 2015年02月27日 18:11:10 | martius | create |