Skip to content

Add close() to multiprocessing.Process #74781

Closed

Description

@pitrou
BPO 30596
Nosy @pitrou, @vstinner, @JimJJewett, @applio
PRs
  • Fix bpo-30596: Add close() method to multiprocessing.Process #2010
  • 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 = <Date 2017-06-24.17:22:45.256>
    created_at = <Date 2017-06-08.10:25:03.845>
    labels = ['3.7', 'type-feature', 'library']
    title = 'Add close() to multiprocessing.Process'
    updated_at = <Date 2017-06-26.11:48:35.111>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2017-06-26.11:48:35.111>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-06-24.17:22:45.256>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2017-06-08.10:25:03.845>
    creator = 'pitrou'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30596
    keywords = []
    message_count = 10.0
    messages = ['295396', '295461', '295741', '295750', '295783', '295784', '295803', '296779', '296877', '296878']
    nosy_count = 5.0
    nosy_names = ['pitrou', 'vstinner', 'asksol', 'Jim.Jewett', 'davin']
    pr_nums = ['2010']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue30596'
    versions = ['Python 3.7']

    Activity

    1. pitrou commented on Jun 8, 2017

      @pitrou
      MemberAuthor

      multiprocessing.Process (actually, the _popen object attached to it) has a GC-based finalizer to release system resources (such as fds). However, it would be nice to be able to release those resources in a timely manner. Adding a close() method would let users do that. What do you think?

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancement
      on Jun 8, 2017
    3. pitrou commented on Jun 8, 2017

      @pitrou
      MemberAuthor

      close() wouldn't terminate the underlying process, so the process would still exist (and wouldn't easily be stoppable from Python anymore) if you were to call close() before terminate() or join().

      Perhaps we should instead mandate people call join() before close()?

    4. jimjjewett commented on Jun 12, 2017

      jimjjewettmannequin
      Mannequin

      Then why not just call join as part of the default close method?

    5. pitrou commented on Jun 12, 2017

      @pitrou
      MemberAuthor

      That's a good question. close() methods on other objects tend to avoid taking an infinite amount of time :-) But then, Process objects are different enough that they don't need to follow that rule.

    6. jimjjewett commented on Jun 12, 2017

      jimjjewettmannequin
      Mannequin

      Could join be called in a background thread, or even asynchronously? That
      seems like mixing paradigms, but ...

      On Jun 12, 2017 3:15 AM, "Antoine Pitrou" <report@bugs.python.org> wrote:

      Antoine Pitrou added the comment:

      That's a good question. close() methods on other objects tend to avoid
      taking an infinite amount of time :-) But then, Process objects are
      different enough that they don't need to follow that rule.

      ----------


      Python tracker <report@bugs.python.org>
      <http://bugs.python.org/issue30596\>


    7. pitrou commented on Jun 12, 2017

      @pitrou
      MemberAuthor

      I want close() to be deterministic. So I guess we have two simple possibilities:

      1. close() raises if the process is still alive
      2. close() calls join() implicitly if the process is still alive
    8. pitrou commented on Jun 12, 2017

      @pitrou
      MemberAuthor

      I've decided it's better to raise a ValueError if the child process hasn't stopped yet. After all, join() alone may have no effect: often you want to send the process a signal (a literal signal in UNIX terms, or a figurative signal such as write something on a socket, etc.) to ask it to terminate gently.

      I'm gonna update the PR soon.

    9. pitrou commented on Jun 24, 2017

      @pitrou
      MemberAuthor

      New changeset 13e96cc by Antoine Pitrou in branch 'master':
      Fix bpo-30596: Add close() method to multiprocessing.Process (bpo-2010)
      13e96cc

    10. vstinner commented on Jun 26, 2017

      @vstinner
      Member

      Since the object now has a close() method, would it make sense to emit a ResourceWarning if it's not closed explicitly? As I did recently in subprocess.Popen destructor.

    11. pitrou commented on Jun 26, 2017

      @pitrou
      MemberAuthor

      I don't think so. It is ok to let the GC delete the resources by itself. close() is just there for people who want to ensure whatever small amount of resources (a file descriptor, mostly) are released timely.

    12. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions