test: Use asyncio.SelectorEventLoop() over deprecated asyncio.WindowsSelectorEventLoopPolicy(), move loop creation #34820

pull maflcko wants to merge 2 commits into bitcoin:master from maflcko:2603-test-windows-revert changing 2 files +2 −4
  1. maflcko commented at 11:11 am on March 13, 2026: member

    It is deprecated according to https://docs.python.org/3.14/library/asyncio-policy.html#asyncio.WindowsSelectorEventLoopPolicy The replacement exists since python 3.7

    Also, move the event loop creation to happen in the thread that runs the loop.

  2. DrahtBot renamed this:
    test: Use asyncio.SelectorEventLoop() over deprecated asyncio.SelectorEventLoop()
    test: Use asyncio.SelectorEventLoop() over deprecated asyncio.SelectorEventLoop()
    on Mar 13, 2026
  3. DrahtBot added the label Tests on Mar 13, 2026
  4. DrahtBot commented at 11:11 am on March 13, 2026: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK l0rinc, sedited

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

  5. test: Use asyncio.SelectorEventLoop() over deprecated asyncio.WindowsSelectorEventLoopPolicy() fa9168ffcd
  6. maflcko renamed this:
    test: Use asyncio.SelectorEventLoop() over deprecated asyncio.SelectorEventLoop()
    test: Use asyncio.SelectorEventLoop() over deprecated asyncio.WindowsSelectorEventLoopPolicy()
    on Mar 13, 2026
  7. maflcko force-pushed on Mar 13, 2026
  8. DrahtBot added the label CI failed on Mar 13, 2026
  9. in test/functional/test_framework/p2p.py:743 in fa9168ffcd
    739@@ -740,9 +740,7 @@ def __init__(self):
    740 
    741         NetworkThread.listeners = {}
    742         NetworkThread.protos = {}
    743-        if platform.system() == 'Windows':
    744-            asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
    745-        NetworkThread.network_event_loop = asyncio.new_event_loop()
    746+        NetworkThread.network_event_loop = asyncio.SelectorEventLoop() if platform.system() == "Windows" else asyncio.new_event_loop()
    


    l0rinc commented at 12:15 pm on March 13, 2026:
    Removing the deprecation seems like a good start, but my understanding is that __init__ happens before thread.start(), and run() after it, so the event loop would still be created on the main thread and then run on the worker thread. My understanding is that this potential cross-thread handoff could still be the suspected source of flakiness.

    maflcko commented at 12:49 pm on March 13, 2026:
    Hmm, ok, I’ll move it as well.
  10. DrahtBot removed the label CI failed on Mar 13, 2026
  11. test: Move event loop creation to network thread
    This should fix https://github.com/bitcoin/bitcoin/issues/34367
    
    I am not familiar with Windows sockets thread-safety, but creating the
    event loop on the main thread, and running it in the network thread
    could lead to a fast abort in Python on Windows (without any stderr):
    
    ```
    77/276 - wallet_txn_clone.py failed, Duration: 1 s
    
    stdout:
    2025-12-10T08:04:27.500134Z TestFramework (INFO): PRNG seed is: 4018092284830106117
    
    stderr:
    
    Combine the logs and print the last 99999999 lines ...
    ============
    Combined log for D:\a\_temp/test_runner_₿_🏃_20251210_075632/wallet_txn_clone_196:
    ============
     test  2025-12-10T08:04:27.500134Z TestFramework (INFO): PRNG seed is: 4018092284830106117
     test  2025-12-10T08:04:27.500433Z TestFramework (DEBUG): Setting up network thread
    ```
    
    Also, I couldn't find any docs that require the loop must be created on
    the thread that runs them:
    
    * https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.new_event_loop
    * https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.run_forever
    
    However, the patch seems trivial to review, harmless, and easy to
    revert, so it may be a good try to fix the intermittent Windows Python
    crash.
    fa050da980
  12. maflcko renamed this:
    test: Use asyncio.SelectorEventLoop() over deprecated asyncio.WindowsSelectorEventLoopPolicy()
    test: Use asyncio.SelectorEventLoop() over deprecated asyncio.WindowsSelectorEventLoopPolicy(), move loop creation
    on Mar 13, 2026
  13. l0rinc commented at 8:31 pm on March 13, 2026: contributor

    ACK fa050da9805d5388ec74e2e0f92e59e861f11918

    The change seems low-risk and makes sense based on my limited understanding of the situation. Checked the related tests and they’re passing on Windows and Mac.

  14. fanquake requested review from willcl-ark on Mar 15, 2026
  15. maflcko commented at 1:31 pm on March 16, 2026: member
    cc @hebasto Was there a reason for you to pick asyncio.WindowsSelectorEventLoopPolicy() over asyncio.SelectorEventLoop(), when initially adding this? Just curious, fine if you don’t recall.
  16. hebasto commented at 2:13 pm on March 16, 2026: member

    cc @hebasto Was there a reason for you to pick asyncio.WindowsSelectorEventLoopPolicy() over asyncio.SelectorEventLoop(), when initially adding this? Just curious, fine if you don’t recall.

    I genuinely don’t recall.

  17. sedited approved
  18. sedited commented at 5:18 pm on March 18, 2026: contributor
    ACK fa050da9805d5388ec74e2e0f92e59e861f11918
  19. sedited merged this on Mar 18, 2026
  20. sedited closed this on Mar 18, 2026

  21. maflcko deleted the branch on Mar 19, 2026
  22. fanquake referenced this in commit c7127f21df on Mar 19, 2026
  23. fanquake referenced this in commit 72d6c88165 on Mar 19, 2026
  24. fanquake commented at 5:36 am on March 19, 2026: member
    Backported to 31.x in #34800.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-05 12:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me