Skip to content

Commit

Permalink
Only set signal handlers if outside of a context manager:
Browse files Browse the repository at this point in the history
- 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(...))``.
  • Loading branch information
fselmo committed Jan 14, 2025
1 parent 3337b5b commit aefb880
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 4 additions & 1 deletion web3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,10 @@ def socket(self) -> PersistentConnection:
)
def __await__(self) -> Generator[Any, None, Self]:
async def __async_init__() -> Self:
await self.provider.connect()
provider = cast("PersistentConnectionProvider", self.provider)
await provider.connect()
# set signal handlers since not within a context manager
provider._set_signal_handlers()
return self

return __async_init__().__await__()
Expand Down
1 change: 0 additions & 1 deletion web3/providers/persistent/persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ async def connect(self) -> None:
self.logger.info(
f"Successfully connected to: {self.get_endpoint_uri_or_ipc_path()}"
)
self._set_signal_handlers()
break
except (WebSocketException, OSError) as e:
if _connection_attempts == self._max_connection_retries:
Expand Down

0 comments on commit aefb880

Please sign in to comment.