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.
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.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
See the guideline for information on the review process.
| Type | Reviewers |
|---|---|
| ACK | l0rinc |
If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.
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()
__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.
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.
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.