Skip to content

multiprocessing async .get() hangs if the pool is terminated #126743

Description

@mdavis-xyz

Bug report

Bug description:

MWE

Steps to reproduce:

import multiprocessing
from time import sleep

with multiprocessing.Pool() as p:
    result = p.apply_async(sleep, (1,))
result.get()

Expected behavior:

Either:

  • result is returned. (Pool().__exit__ waits for every async task to finish); or
  • some kind of exception is raised when .get() is called outside with Pool()

Comments

This is the same as #79659. That was marked as completed in 2021. However it seems the issue is still present.

CPython versions tested on:

3.12, 3.13, 3.14

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bug
    on Nov 12, 2024
  2. added
    stdlib
    on Nov 12, 2024
  3. Zheaoli commented on Nov 12, 2024

    @Zheaoli
    Contributor

    Confirmed on main branch.

    I think we need to think about @vstinner #11139 . It's clean and useful I think

  4. YvesDup commented on Apr 29, 2025

    @YvesDup
    Contributor

    I think we need to think about @vstinner #11139 . It's clean and useful I think

    I agree, but I'm thinking of something simpler: at the begining of the ApplyResult.get method, we just have to test if pool._state is terminated (or closed), and then raises a RuntimeError exception.

    EDIT: This solution could trigger a data race, It's a bad idea. Sorry for the noise.

  5. YvesDup commented on May 12, 2025

    @YvesDup
    Contributor

    @Zheaoli would you want to use the @vstinner #11139 old aborted proposition as a new PR ?

  6. added a commit that references this issue on Nov 30, 2026
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

    stdlibtopic-multiprocessingtype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions