Skip to content

Commit 3337b5b

Browse files
committed
Get current loop within the extended signal handler:
- This had some side effects when running `pytest` since they have their own signal handler. If persistent connection provider tests were run along with any other tests, the disconnect task would interfere with the other handler. - If we get the current loop from within the extended signal handler, we can avoid issues like the one above.
1 parent 12c9d83 commit 3337b5b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

web3/providers/persistent/persistent.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,13 @@ async def _provider_specific_socket_reader(self) -> RPCResponse:
270270
raise NotImplementedError("Must be implemented by subclasses")
271271

272272
def _set_signal_handlers(self) -> None:
273-
loop = asyncio.get_event_loop()
274-
275273
def extended_handler(sig: int, frame: Any, existing_handler: Any) -> None:
276-
loop.create_task(self.disconnect())
274+
loop = asyncio.get_event_loop()
277275

278276
# invoke the existing handler, if callable
279277
if callable(existing_handler):
280278
existing_handler(sig, frame)
279+
loop.create_task(self.disconnect())
281280

282281
existing_sigint_handler = signal.getsignal(signal.SIGINT)
283282
existing_sigterm_handler = signal.getsignal(signal.SIGTERM)

0 commit comments

Comments
 (0)