mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-05 02:33:07 +02:00
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.
Github-Pull: #34820
Rebased-From: fa050da980
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user