← 输入框|github.com|刷新
Skip to content

ProcessPoolExecutor deadlock on KeyboardInterrupt #70096

Open

Description

@jacksontj
mannequin
BPO 25908
Nosy @applio
Dependencies
  • bpo-22393: multiprocessing.Pool shouldn't hang forever if a worker process dies unexpectedly
  • Files
  • worker_ignore_interrupt.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 = None
    created_at = <Date 2015-12-18.19:41:10.721>
    labels = ['type-bug']
    title = 'ProcessPoolExecutor deadlock on KeyboardInterrupt'
    updated_at = <Date 2015-12-27.17:11:24.197>
    user = 'https://bugs.python.org/jacksontj'

    bugs.python.org fields:

    activity = <Date 2015-12-27.17:11:24.197>
    actor = 'davin'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2015-12-18.19:41:10.721>
    creator = 'jacksontj'
    dependencies = ['22393']
    files = ['41358']
    hgrepos = []
    issue_num = 25908
    keywords = ['patch']
    message_count = 4.0
    messages = ['256703', '256705', '256711', '257085']
    nosy_count = 2.0
    nosy_names = ['davin', 'jacksontj']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue25908'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6']

    Activity

    1. jacksontj commented on Dec 18, 2015

      jacksontjmannequin
      MannequinAuthor

      If a KeyboardInterrupt is received while a worker process is grabbing an item off of the queue that worker process dies with an uncaught exception. This means that the ProcessPool now has lost a process, and currently has no mechanism to recover from dead processes. This is especially noticeable if the CallItem is relatively large (as the call_queue.get() includes all the pickle time).

      A simple fix is to have the worker process not do anything with the keyboard interrupt-- since it would have no idea what to do. This cannot be implemented with a regular try/except-- as the item will be partially pulled off of the queue and lost. My proposed fix is to disable the SIGINT handler in the worker process while getting items off of the queue.

      An alternate approach is to actually change multiprocessing.Queue.get() to leave the item on the queue if it is interrupted with a keyboard interrupt

      to this is to catch the KeyboardInterrupt and simply continue on-- then we can rely on the caller to do the cleanup.This cannot be done by simply

      Proposed patch attached

    2. added
      type-bug
      on Dec 18, 2015
    3. jacksontj commented on Dec 18, 2015

      jacksontjmannequin
      MannequinAuthor

      Seems that I accidentally hit submit, so let me finish the last bit of my message here:

      An alternate approach is to actually change multiprocessing.Queue.get() to leave the item on the queue if it is interrupted with a keyboard interrupt. Then the worker process could handle the exception in a more meaningful way

      It is also interesting to note, that in the event that the caller gets a KeyboardInterrupt there is no terminate method which would let you kill jobs before they run. I'm not certain if that should be included in this issue, or if I should file a separate ticket since they are related but different.

    4. jacksontj commented on Dec 18, 2015

      jacksontjmannequin
      MannequinAuthor

      Some more investigation, it seems that the alternate Queue fix is a non-starter. From my investigation it seems that the ProcessPoolExecutor is assuming that multiprocess.Queue is gauranteed delivery, and it isn't (because of the pickling). So the issue is that the worker process drops the message if its interrupted while unpickling and the Pool class has no idea-- and assumes that the job is still running. With that being said it seems like my attached patch is probably the most reasonable fix without a major rework of how the ProcessPoolExecutor works.

    5. applio commented on Dec 27, 2015

      @applio
      Member

      Noting the connection to bpo-22393.

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

      topic-multiprocessingtype-bug

      Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions