Skip to content

Add worker process lifetime to multiprocessing.Pool - patch included #51212

Closed

Description

@charlesc
mannequin
BPO 6963
Files
  • worker-lifetime-python2.6.2.patch: 4th version of patch adding worker lifetime to multiprocessing.Pool
  • mp_patch_6963_trunk.patch: trunk based patch
  • 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 2010-01-27.03:36:56.117>
    created_at = <Date 2009-09-22.02:28:11.774>
    labels = ['type-feature', 'library']
    title = 'Add worker process lifetime to multiprocessing.Pool - patch included'
    updated_at = <Date 2010-01-27.03:36:56.116>
    user = 'https://bugs.python.org/charlesc'

    bugs.python.org fields:

    activity = <Date 2010-01-27.03:36:56.116>
    actor = 'jnoller'
    assignee = 'jnoller'
    closed = True
    closed_date = <Date 2010-01-27.03:36:56.117>
    closer = 'jnoller'
    components = ['Library (Lib)']
    creation = <Date 2009-09-22.02:28:11.774>
    creator = 'charlesc'
    dependencies = []
    files = ['15940', '16004']
    hgrepos = []
    issue_num = 6963
    keywords = ['patch', 'needs review']
    message_count = 18.0
    messages = ['92971', '92987', '92999', '93191', '93517', '93916', '93920', '93921', '93923', '95243', '95250', '97832', '97835', '98032', '98129', '98313', '98382', '98402']
    nosy_count = 2.0
    nosy_names = ['jnoller', 'charlesc']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue6963'
    versions = ['Python 2.7', 'Python 3.2']

    Activity

    1. charlesc commented on Sep 22, 2009

      charlescmannequin
      MannequinAuthor

      Worker processes with multiprocessing.Pool live for the duration of the
      Pool. If the tasks they run happen to leak memory (from a C extension
      module, or from creating cycles of unreachable objects, etc) or open
      files or other resources, there's no easy way to clean them up.

      Similarly, if one task passed to the pool allocates a large amount of
      memory, but further tasks are small, that additional memory isn't
      returned to the system because the process involved hasn't exited.

      A common approach to this problem (as used by Apache, mod_wsgi, and
      various other software) is to allow worker processes to exit (and be
      replaced with fresh processes) after completing a specified amount of
      work. The attached patch (against Python 2.6.2, but applies to various
      other versions with some fuzz) implements this as optional new behaviour
      in multiprocessing.Pool(). An additional optional argument is specified
      for the maximum number of tasks a worker process performs before it
      exits and is replaced with a fresh worker process.

    2. added
      stdlib
      type-feature
      on Sep 22, 2009
    3. jnoller commented on Sep 22, 2009

      jnollermannequin
      Mannequin

      Hi Charles; I don't see a doc update for this (see multiprocessing.rst) or
      unit tests. I'm not against it, but before I can commit this, I'll need
      those things

    4. charlesc commented on Sep 22, 2009

      charlescmannequin
      MannequinAuthor

      Alright, I'll add those. Thanks for looking at it; first pass was
      mostly to ensure it wouldn't be wasted work.

    5. charlesc commented on Sep 28, 2009

      charlescmannequin
      MannequinAuthor

      Updated patch attached; handles some of the Pool methods that weren't
      handled before. Now includes documentation and unit test additions as well.

    6. charlesc commented on Oct 4, 2009

      charlescmannequin
      MannequinAuthor

      Jesse: this is ready for your review now. Thanks,

      Charles

    7. charlesc commented on Oct 13, 2009

      charlescmannequin
      MannequinAuthor

      Can someone review this patch? I believe it's sufficient for inclusion
      now, as it includes docs and unit tests, but if anything about it
      requires further attention I'd be happy to listen to change requests.
      We'd like get this into mainline where everyone can benefit rather than
      continuing to maintain it out-of-tree.

    8. jnoller commented on Oct 13, 2009

      jnollermannequin
      Mannequin

      I plan on reviewing the patch once my work with PyCon is completed, which
      should be within the next few weeks. The next release this would show up
      in (2.7/3.2) is not for some time.

    9. charlesc commented on Oct 13, 2009

      charlescmannequin
      MannequinAuthor

      Okay, thanks, Jesse. Didn't realize the Con was on.

    10. jnoller commented on Oct 13, 2009

      jnollermannequin
      Mannequin

      Well, it's in feb, but I'm involved in some intense planning right now.

    11. charlesc commented on Nov 14, 2009

      charlescmannequin
      MannequinAuthor

      Hi Jesse -- Any chance you'll be able to review this in time for it to
      make it into trunk for the 2.7 alpha release?

      Charles

    12. jnoller commented on Nov 14, 2009

      jnollermannequin
      Mannequin

      On Sat, Nov 14, 2009 at 11:43 AM, Charles Cazabon
      <report@bugs.python.org> wrote:

      Charles Cazabon <charlesc-python@pyropus.ca> added the comment:

      Hi Jesse -- Any chance you'll be able to review this in time for it to
      make it into trunk for the 2.7 alpha release?

      2.7 isn't slated until next year some time, so yes.

    13. charlesc commented on Jan 15, 2010

      charlescmannequin
      MannequinAuthor

      Ping... two alphas into 2.7. Have you had a chance to review this functionality?

      Thanks.

    14. jnoller commented on Jan 15, 2010

      jnollermannequin
      Mannequin

      I'm fine with the functionality; I'm going to test it out and look at committing it by mid-week next week. I apologize, I've been pretty maxed out.

    15. charlesc commented on Jan 18, 2010

      charlescmannequin
      MannequinAuthor

      No problem, Jesse, I realize you're busy.

      I've updated the patch very slightly to handle an issue I had where the worker maintainer hung once.

    16. jnoller commented on Jan 22, 2010

      jnollermannequin
      Mannequin

      I'm working on this now; I'm going to need to port the patch to trunk before moving forward with it. Shouldn't take me long.

    17. jnoller commented on Jan 26, 2010

      jnollermannequin
      Mannequin

      Attached is the ported patch for Python 2.7/trunk. Please review it to make sure I didn't completely flub anything. I noticed you had forgotten the maxtasksperchild argument in the unit test, so I added that. I also expanded the docs a little but, paraphrasing your original post w.r.t to the justification.

      Let me know what you think, or if you have issues. Once you give the go ahead, I will commit to trunk and then merge to Py3k.

      Once again, thanks for the patch

    18. charlesc commented on Jan 26, 2010

      charlescmannequin
      MannequinAuthor

      Thanks, Jesse -- it looks good. If there are bugs remaining in the patch, they're mine and not yours.

    19. jnoller commented on Jan 27, 2010

      jnollermannequin
      Mannequin

      Committed to trunk in r77794
      Merged to Py3k in r77795

    20. 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

      stdlibtype-feature

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions