From fa9168ffcd6354db6daf759ace123a88fb60cbb2 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Fri, 13 Mar 2026 10:44:47 +0100 Subject: [PATCH 1/2] test: Use asyncio.SelectorEventLoop() over deprecated asyncio.WindowsSelectorEventLoopPolicy() --- test/functional/test_framework/p2p.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index 7a7cce6176c..bd8a1da75f3 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -740,9 +740,7 @@ class NetworkThread(threading.Thread): NetworkThread.listeners = {} NetworkThread.protos = {} - if platform.system() == 'Windows': - asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) - NetworkThread.network_event_loop = asyncio.new_event_loop() + NetworkThread.network_event_loop = asyncio.SelectorEventLoop() if platform.system() == "Windows" else asyncio.new_event_loop() def run(self): """Start the network thread.""" From fa050da9805d5388ec74e2e0f92e59e861f11918 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Fri, 13 Mar 2026 10:07:58 +0100 Subject: [PATCH 2/2] test: Move event loop creation to network thread MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- test/functional/test_framework/p2p.py | 2 +- test/functional/test_framework/test_framework.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index bd8a1da75f3..fae4eb94c21 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -740,10 +740,10 @@ class NetworkThread(threading.Thread): NetworkThread.listeners = {} NetworkThread.protos = {} - NetworkThread.network_event_loop = asyncio.SelectorEventLoop() if platform.system() == "Windows" else asyncio.new_event_loop() def run(self): """Start the network thread.""" + NetworkThread.network_event_loop = asyncio.SelectorEventLoop() if platform.system() == "Windows" else asyncio.new_event_loop() self.network_event_loop.run_forever() def close(self, *, timeout): diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index fb0fc0af6b8..95bfc964d60 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -260,7 +260,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): self.log.debug('Setting up network thread') self.network_thread = NetworkThread() self.network_thread.start() - self.wait_until(lambda: self.network_thread.network_event_loop.is_running()) + self.wait_until(lambda: self.network_thread.network_event_loop is not None and self.network_thread.network_event_loop.is_running()) if self.options.usecli: if not self.supports_cli: