|
1 | 1 | import abc |
2 | 2 | import asyncio |
| 3 | +from logging import getLogger |
3 | 4 | from typing import Any, AsyncIterator, Awaitable, Callable, Dict |
4 | 5 |
|
5 | 6 | from anyio import create_task_group |
|
8 | 9 | from .layout import Layout, LayoutEvent, LayoutUpdate |
9 | 10 | from .utils import HasAsyncResources, async_resource |
10 | 11 |
|
| 12 | +logger = getLogger(__name__) |
| 13 | + |
11 | 14 | SendCoroutine = Callable[[Any], Awaitable[None]] |
12 | 15 | RecvCoroutine = Callable[[], Awaitable[LayoutEvent]] |
13 | 16 |
|
@@ -49,12 +52,20 @@ async def run(self, send: SendCoroutine, recv: RecvCoroutine, context: Any) -> N |
49 | 52 | return None |
50 | 53 |
|
51 | 54 | async def _outgoing_loop(self, send: SendCoroutine, context: Any) -> None: |
52 | | - while True: |
53 | | - await send(await self._outgoing(self.layout, context)) |
| 55 | + try: |
| 56 | + while True: |
| 57 | + await send(await self._outgoing(self.layout, context)) |
| 58 | + except Exception: |
| 59 | + logger.info("Failed to send outgoing update", exc_info=True) |
| 60 | + raise |
54 | 61 |
|
55 | 62 | async def _incoming_loop(self, recv: RecvCoroutine, context: Any) -> None: |
56 | | - while True: |
57 | | - await self._incoming(self.layout, context, await recv()) |
| 63 | + try: |
| 64 | + while True: |
| 65 | + await self._incoming(self.layout, context, await recv()) |
| 66 | + except Exception: |
| 67 | + logger.info("Failed to receive incoming event", exc_info=True) |
| 68 | + raise |
58 | 69 |
|
59 | 70 | @abc.abstractmethod |
60 | 71 | async def _outgoing(self, layout: Layout, context: Any) -> Any: |
|
0 commit comments