Skip to content

multiprocessing.connection.wait high CPU load with empty object_list #145587

Closed

Description

@danielhrisca

Bug report

Bug description:

 from multiprocessing.conenction import wait
 import os
 from time import time
 
 print(os.getpid())
 start = t
 
 while True:

    for pipe in wait([], 1):
        pass
    print(time()-t)

multiprocessing.connection.wait causes 100% CPU load if the object list is empty; otherwise the CPU load very low

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Linked PRs

Activity

  1. danielhrisca commented on Mar 6, 2026

    @danielhrisca
    Author

    I've also tested with Python 3.12.3 on Linux and there the CPU load is very low with an empty object_list

  2. YvesDup commented on Mar 6, 2026

    @YvesDup
    Contributor

    Could you provide a runnable and complete example, please ?

  3. danielhrisca commented on Mar 6, 2026

    @danielhrisca
    Author

    I've updated the example. The CPU load is high even without the print statement

    If I run it on Linux I see that the wait call takes in the order of ms

    35.23168587684631
    36.233556509017944
    37.2396240234375
    38.24300479888916
    39.2457799911499
    40.2487576007843
    41.33868384361267
    42.34193706512451
    43.34582734107971
    44.3491108417511
    

    The same example when running on Windows produces this output

    59.44313287734985
    59.44317555427551
    59.443217039108276
    59.44330191612244
    59.44336795806885
    59.44341683387756
    59.44345951080322
    59.44350242614746
    59.443572759628296
    59.443615674972534
    59.4436571598053
    
  4. added a commit that references this issue on Mar 6, 2026
  5. Shrey-N commented on Mar 6, 2026

    @Shrey-N
    Contributor

    Hiya @danielhrisca I have verified this issue with a script on Windows.

    The issue is in Lib/multiprocessing/connection.py,
    While the Unix implementation uses selectors.select, the Windows version attempts to build a handle list. If that list is empty, it returns an empty result immediately without ever hitting a blocking call.

    I am submitting a PR in a minute that adds a check for an empty object_list to ensure the function properly respects the timeout before returning.

    Reproduction Script:-

    from multiprocessing.connection import wait
    import time
    
    start = time.time()
    # This should take approx 1 second, but returns instantly on Windows
    wait([], 1.0) 
    print(f"Elapsed: {time.time() - start:.4f}s")
    

    Hope the PR, and explanation helps :)

  6. added a commit that references this issue on Mar 6, 2026
  7. added a commit that references this issue on Mar 11, 2026
  8. added a commit that references this issue on Apr 25, 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

    OS-windowsstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions