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

Possible multiprocessing deadlock when placing too many objects in Queue() #78321

Closed
fhstoica mannequin opened this issue Jul 17, 2018 · 3 comments
Closed

Possible multiprocessing deadlock when placing too many objects in Queue() #78321

fhstoica mannequin opened this issue Jul 17, 2018 · 3 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@fhstoica
Copy link
Mannequin

fhstoica mannequin commented Jul 17, 2018

BPO 34140
Nosy @pitrou, @applio, @zhangyangyu, @fhstoica
Files
  • IssuesWithQueueMultiProcessing.tar.bz
  • 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 2018-07-17.16:51:46.885>
    created_at = <Date 2018-07-17.14:21:19.056>
    labels = ['type-bug', 'invalid']
    title = 'Possible multiprocessing deadlock when placing too many objects in Queue()'
    updated_at = <Date 2018-07-17.16:51:46.883>
    user = 'https://github.com/fhstoica'

    bugs.python.org fields:

    activity = <Date 2018-07-17.16:51:46.883>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-07-17.16:51:46.885>
    closer = 'pitrou'
    components = []
    creation = <Date 2018-07-17.14:21:19.056>
    creator = 'fhstoica'
    dependencies = []
    files = ['47702']
    hgrepos = []
    issue_num = 34140
    keywords = []
    message_count = 3.0
    messages = ['321832', '321842', '321843']
    nosy_count = 4.0
    nosy_names = ['pitrou', 'davin', 'xiang.zhang', 'fhstoica']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue34140'
    versions = ['Python 3.5', 'Python 3.6']

    @fhstoica
    Copy link
    Mannequin Author

    fhstoica mannequin commented Jul 17, 2018

    I am trying to use the multiprocessing module for a simulation on a spherical lattice, but the process hangs when the lattice is too large.

    In the file IssuesWithQueueMultiProcessing.py, the method createLattice(), use either "return(I4)" for the small lattice or "return(I5)" for the large lattice.

    Running the script when using the large lattice causes the process to hang while for the small lattice it works fine. I have tested with Python 3.5.2 and 3.6.1 and the behavior is the same in both versions.

    @fhstoica fhstoica mannequin added the performance Performance or resource usage label Jul 17, 2018
    @pitrou
    Copy link
    Member

    pitrou commented Jul 17, 2018

    The problem is you're joining the child processes before draining the queue in the parent.

    Generally, instead of building your own kind of synchronization like this, I would recommend you use the higher-level abstractions provided by multiprocessing.Pool or concurrent.futures.ProcessPoolExecutor.

    By the way, this issue is mentioned precisely in the documentation:

    """
    As mentioned above, if a child process has put items on a queue (and it has not used JoinableQueue.cancel_join_thread), then that process will not terminate until all buffered items have been flushed to the pipe.

    This means that if you try joining that process you may get a deadlock unless you are sure that all items which have been put on the queue have been consumed. Similarly, if the child process is non-daemonic then the parent process may hang on exit when it tries to join all its non-daemonic children.
    """

    (from https://docs.python.org/3/library/multiprocessing.html#pipes-and-queues)

    @pitrou
    Copy link
    Member

    pitrou commented Jul 17, 2018

    Closing as not a bug.

    @pitrou pitrou closed this as completed Jul 17, 2018
    @pitrou pitrou added invalid type-bug An unexpected behavior, bug, or error and removed performance Performance or resource usage labels Jul 17, 2018
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant