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

multiprocessing maxtasksperchild=1 + logging = task loss #67467

Open
nelson mannequin opened this issue Jan 20, 2015 · 3 comments
Open

multiprocessing maxtasksperchild=1 + logging = task loss #67467

nelson mannequin opened this issue Jan 20, 2015 · 3 comments
Labels
stdlib Python modules in the Lib dir topic-multiprocessing type-bug An unexpected behavior, bug, or error

Comments

@nelson
Copy link
Mannequin

nelson mannequin commented Jan 20, 2015

BPO 23278
Nosy @vsajip, @tirkarthi
Files
  • bug-demo.py: demonstration of bug
  • 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-01-20.02:02:52.352>
    labels = ['type-bug', 'library']
    title = 'multiprocessing maxtasksperchild=1 + logging = task loss'
    updated_at = <Date 2018-09-17.12:52:44.847>
    user = 'https://bugs.python.org/nelson'

    bugs.python.org fields:

    activity = <Date 2018-09-17.12:52:44.847>
    actor = 'xtreak'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2015-01-20.02:02:52.352>
    creator = 'nelson'
    dependencies = []
    files = ['37781']
    hgrepos = []
    issue_num = 23278
    keywords = []
    message_count = 2.0
    messages = ['234336', '234392']
    nosy_count = 4.0
    nosy_names = ['vinay.sajip', 'sbt', 'nelson', 'xtreak']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue23278'
    versions = ['Python 2.7', 'Python 3.4']

    @nelson
    Copy link
    Mannequin Author

    nelson mannequin commented Jan 20, 2015

    I have a demonstration of a problem where the combination of multiprocessing with maxtasksperchild=1 and the Python logging library causes tasks to occasionally get lost. The bug might be related to bpo-22393 or bpo-6721, but I'm not certain. bpo-10037 and bpo-9205 also might be relevant. I've attached sample code, it can also be found at https://gist.github.com/NelsonMinar/022794b6a709ea5b7682

    My program uses Pool.imap_unordered() to execute 200 tasks. Each worker task writes a log message and sleeps a short time. The master process uses a timeout on next() to log a status message occasionally.

    When it works, 200 jobs are completed quickly. When it breaks, roughly 195 of 200 jobs will have completed and next() never raises StopIteration.

    If everything logs to logging.getLogger() and maxtasksperchild=1, it usually breaks. It appears that sometimes jobs just get lost and don't complete. We've observed that with maxtasksperchild=1 sometimes a new worker process gets created but no work assigned to it. When that happens the task queue never runs to completion.

    If we log straight to stderr or don't set maxtasksperchild, the run completes.

    The bug has been observed in Python 2.7.6 and Python 3.4.0 on Ubuntu 14.04

    This is a distillation of much more complex application-specific code. Discussion of the bug and original code can be found at

    openaddresses/machine#51
    https://github.com/openaddresses/machine/blob/7c3d0fba8ba0915af2101ace45dfaf5519d5ad85/openaddr/jobs.py

    Thank you, Nelson

    @nelson nelson mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 20, 2015
    @nelson
    Copy link
    Mannequin Author

    nelson mannequin commented Jan 20, 2015

    Doing some more testing, I noticed that if I ask multiprocessing to also log, the problem stops occurring. If I configure multiprocessing.log_to_stderr() instead, the error still occurs.

    Here's how I configured multiprocessing logging that makes the problem go away. This goes right at the top of the main() function.

        mp_logger = multiprocessing.get_logger()
        mp_logger.propagate=True
        mp_logger.setLevel(logging.DEBUG)

    @saito828koki
    Copy link
    Contributor

    FWIW I cannot reproduce the same bug.(tested on Python 3.10.6, macOS Montrey 12.6)

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir topic-multiprocessing type-bug An unexpected behavior, bug, or error
    Projects
    Status: No status
    Status: No status
    Development

    No branches or pull requests

    2 participants