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.Pool.__enter__() should raise an exception if called twice #79658

vstinner opened this issue Dec 12, 2018 · 3 comments
3.8 only security fixes stdlib Python modules in the Lib dir


Copy link

BPO 35477
Nosy @vstinner
  • bpo-35477: multiprocessing.Pool.__enter__() fails if called twice #11134
  • 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-12-13.01:15:47.499>
    created_at = <Date 2018-12-12.23:08:12.351>
    labels = ['3.8', 'library']
    title = 'multiprocessing.Pool.__enter__() should raise an exception if called twice'
    updated_at = <Date 2018-12-13.01:15:47.498>
    user = '' fields:

    activity = <Date 2018-12-13.01:15:47.498>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-12-13.01:15:47.499>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2018-12-12.23:08:12.351>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35477
    keywords = ['patch']
    message_count = 3.0
    messages = ['331719', '331720', '331728']
    nosy_count = 1.0
    nosy_names = ['vstinner']
    pr_nums = ['11134']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = ''
    versions = ['Python 3.8']

    Copy link
    Member Author

    On a file, "with file:" fails if it's used a second time:

    fp = open('/etc/issue')
    with fp:
    with fp:

    fails with "ValueError: I/O operation on closed file", because file.__enter__() raises this exception if the file is closed.

    I propose to have the same behavior on multiprocessing.Pool.__enter__() to detect when the multiprocessing API is misused.

    Anyway, after the first "with pool:" block, the pool becomes unusable to schedule now tasks: apply() raise ValueError("Pool not running") in that case for example.

    @vstinner vstinner added 3.8 only security fixes stdlib Python modules in the Lib dir labels Dec 12, 2018
    Copy link
    Member Author

    Currently, the error only occurs when apply() is called:

    import multiprocessing
    def the_test():
        pool = multiprocessing.Pool(1)
        with pool:
            print(pool.apply(int, (2,)))
        with pool:
            print(pool.apply(int, (3,))) # <-- raise here

    I would prefer to get an error on at the second "with pool:" line.

    Copy link
    Member Author

    New changeset 08c2ba0 by Victor Stinner in branch 'master':
    bpo-35477: multiprocessing.Pool.__enter__() fails if called twice (GH-11134)

    @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
    3.8 only security fixes stdlib Python modules in the Lib dir
    None yet

    No branches or pull requests

    1 participant