Skip to content

Commit

Permalink
upgrade anyio - see agronholm/anyio#155
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed Sep 8, 2020
1 parent 3c5c31a commit 69238e0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
32 changes: 4 additions & 28 deletions idom/core/dispatcher.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import abc
import asyncio
from functools import wraps
from typing import Callable, Awaitable, Dict, Any, AsyncIterator, TypeVar, cast
from typing import Callable, Awaitable, Dict, Any, AsyncIterator

from anyio import create_task_group, TaskGroup # type: ignore
from jsonpatch import make_patch, apply_patch
from loguru import logger

from .layout import (
LayoutEvent,
LayoutUpdate,
Layout,
Layout,
)
from .utils import HasAsyncResources, async_resource

Expand Down Expand Up @@ -44,12 +41,8 @@ async def run(self, send: SendCoroutine, recv: RecvCoroutine, context: Any) -> N
This will call :meth:`AbstractLayouTaskGroupTaskGroupt.render` and :meth:`Layout.dispatch`
to render new models and execute events respectively.
"""
await self.task_group.spawn(
_async_log_exceptions(self._outgoing_loop), send, context
)
await self.task_group.spawn(
_async_log_exceptions(self._incoming_loop), recv, context
)
await self.task_group.spawn(self._outgoing_loop, send, context)
await self.task_group.spawn(self._incoming_loop, recv, context)
return None

async def _outgoing_loop(self, send: SendCoroutine, context: Any) -> None:
Expand Down Expand Up @@ -108,7 +101,7 @@ def __init__(self, layout: Layout) -> None:
@async_resource
async def task_group(self) -> AsyncIterator[TaskGroup]:
async with create_task_group() as group:
await group.spawn(_async_log_exceptions(self._render_loop))
await group.spawn(self._render_loop)
yield group

async def run(
Expand Down Expand Up @@ -147,20 +140,3 @@ def _apply_layout_update(doc: Dict[str, Any], update: LayoutUpdate) -> Any:
return apply_patch(
doc, [{**c, "path": update.path + c["path"]} for c in update.changes]
)


_F = TypeVar("_F", bound=Callable[..., Any])


def _async_log_exceptions(function: _F) -> _F:
# BUG: https://github.com/agronholm/anyio/issues/155

@wraps(function)
async def wrapper(*args: Any, **kwargs: Any) -> Any:
try:
return await function(*args, **kwargs)
except Exception:
logger.exception(f"Failure in {function}")
raise

return cast(_F, wrapper)
2 changes: 1 addition & 1 deletion requirements/prod.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
loguru >=0.3.2
typing-extensions >=3.7.4
mypy-extensions >=0.4.3
anyio >=1.3.0
anyio >=1.4.0
async_generator >=1.10; python_version<"3.7"
async_exit_stack >=1.0.1; python_version<"3.7"
jsonpatch >=1.26

0 comments on commit 69238e0

Please sign in to comment.