|
20 | 20 | from hexbytes import ( |
21 | 21 | HexBytes, |
22 | 22 | ) |
23 | | -from websockets.exceptions import ( |
24 | | - ConnectionClosedOK, |
25 | | -) |
26 | 23 |
|
27 | 24 | from web3._utils.batching import ( |
28 | 25 | RequestBatcher, |
@@ -487,7 +484,7 @@ async def send(self, method: RPCEndpoint, params: Any) -> RPCResponse: |
487 | 484 | def _persistent_message_stream(self) -> "_AsyncPersistentMessageStream": |
488 | 485 | return _AsyncPersistentMessageStream(self) |
489 | 486 |
|
490 | | - async def _get_next_message(self) -> Any: |
| 487 | + async def _get_next_message(self) -> Optional[RPCResponse]: |
491 | 488 | return await self._message_stream().__anext__() |
492 | 489 |
|
493 | 490 | async def _message_stream(self) -> AsyncGenerator[RPCResponse, None]: |
@@ -515,12 +512,13 @@ async def _message_stream(self) -> AsyncGenerator[RPCResponse, None]: |
515 | 512 | # if response is an active subscription response, process it |
516 | 513 | yield await self._process_response(response) |
517 | 514 | except TaskNotRunning: |
| 515 | + await asyncio.sleep(0) |
518 | 516 | self._provider._handle_listener_task_exceptions() |
519 | 517 | self.logger.error( |
520 | 518 | "Message listener background task has stopped unexpectedly. " |
521 | 519 | "Stopping message stream." |
522 | 520 | ) |
523 | | - raise StopAsyncIteration |
| 521 | + return |
524 | 522 |
|
525 | 523 | async def _process_response(self, response: RPCResponse) -> RPCResponse: |
526 | 524 | provider = cast(PersistentConnectionProvider, self._provider) |
@@ -586,7 +584,4 @@ def __aiter__(self) -> Self: |
586 | 584 | return self |
587 | 585 |
|
588 | 586 | async def __anext__(self) -> RPCResponse: |
589 | | - try: |
590 | | - return await self.manager._get_next_message() |
591 | | - except ConnectionClosedOK: |
592 | | - raise StopAsyncIteration |
| 587 | + return await self.manager._get_next_message() |
0 commit comments