Skip to content

Commit aefb880

Browse files
committed
Only set signal handlers if outside of a context manager:
- Since context managers can handle signals appropriately, disconnecting after receiving a signal, only set signal handlers if outside of a context manager instantiation i.e. ``await AsyncWeb3(PersistentConnectionProvider(...))``.
1 parent 3337b5b commit aefb880

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Diff for: web3/main.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,10 @@ def socket(self) -> PersistentConnection:
540540
)
541541
def __await__(self) -> Generator[Any, None, Self]:
542542
async def __async_init__() -> Self:
543-
await self.provider.connect()
543+
provider = cast("PersistentConnectionProvider", self.provider)
544+
await provider.connect()
545+
# set signal handlers since not within a context manager
546+
provider._set_signal_handlers()
544547
return self
545548

546549
return __async_init__().__await__()

Diff for: web3/providers/persistent/persistent.py

-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ async def connect(self) -> None:
177177
self.logger.info(
178178
f"Successfully connected to: {self.get_endpoint_uri_or_ipc_path()}"
179179
)
180-
self._set_signal_handlers()
181180
break
182181
except (WebSocketException, OSError) as e:
183182
if _connection_attempts == self._max_connection_retries:

0 commit comments

Comments
 (0)