Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal for asyncio: SubprocessTransport.detach() to detach a process from a transport #67728

Closed
Martiusweb opened this issue Feb 27, 2015 · 3 comments
Labels
pending The issue will be closed if no feedback is provided topic-asyncio type-feature A feature request or enhancement

Comments

@Martiusweb
Copy link
Member

BPO 23540
Nosy @gvanrossum, @vstinner, @1st1, @Martiusweb
Files
  • add-detach-to-subprocess_transport.patch: First try: add a detach() method to SubprocessTransport.
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2015-02-27.18:11:10.238>
    labels = ['type-feature', 'expert-asyncio']
    title = 'Proposal for asyncio: SubprocessTransport.detach() to detach a process from a transport'
    updated_at = <Date 2015-02-27.18:11:10.238>
    user = 'https://github.com/Martiusweb'

    bugs.python.org fields:

    activity = <Date 2015-02-27.18:11:10.238>
    actor = 'martius'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['asyncio']
    creation = <Date 2015-02-27.18:11:10.238>
    creator = 'martius'
    dependencies = []
    files = ['38263']
    hgrepos = []
    issue_num = 23540
    keywords = ['patch']
    message_count = 1.0
    messages = ['236808']
    nosy_count = 4.0
    nosy_names = ['gvanrossum', 'vstinner', 'yselivanov', 'martius']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue23540'
    versions = ['Python 3.3', 'Python 3.4', 'Python 3.5']

    @Martiusweb
    Copy link
    Member Author

    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.

    @Martiusweb Martiusweb added topic-asyncio type-feature A feature request or enhancement labels Feb 27, 2015
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @kumaraditya303
    Copy link
    Contributor

    No activity for ~7 years, I am unclear about the use case for this, marking pending.

    @kumaraditya303 kumaraditya303 added the pending The issue will be closed if no feedback is provided label Sep 9, 2022
    @kumaraditya303
    Copy link
    Contributor

    I am closing this as the use cases requires fork which asyncio doesn't properly supports and there are no comments after the initial issue.

    @kumaraditya303 kumaraditya303 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    pending The issue will be closed if no feedback is provided topic-asyncio type-feature A feature request or enhancement
    Projects
    Status: Done
    Development

    No branches or pull requests

    2 participants