Skip to content

Commit

Permalink
make BlockingPortal.stop sync
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Jul 3, 2021
1 parent 5591099 commit 2adff23
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/anyio/from_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from warnings import warn

from ._core import _eventloop
from ._core._compat import DeprecatedAwaitable
from ._core._eventloop import get_asynclib, get_cancelled_exc_class, threadlocals
from ._core._synchronization import Event
from ._core._tasks import CancelScope, create_task_group
Expand Down Expand Up @@ -130,7 +131,7 @@ async def __aenter__(self) -> 'BlockingPortal':
async def __aexit__(self, exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType]) -> Optional[bool]:
await self.stop()
self.stop()
return await self._task_group.__aexit__(exc_type, exc_val, exc_tb)

def _check_running(self) -> None:
Expand All @@ -143,7 +144,7 @@ async def sleep_until_stopped(self) -> None:
"""Sleep until :meth:`stop` is called."""
await self._stop_event.wait()

async def stop(self, cancel_remaining: bool = False) -> None:
def stop(self, cancel_remaining: bool = False) -> DeprecatedAwaitable:
"""
Signal the portal to shut down.
Expand All @@ -159,6 +160,8 @@ async def stop(self, cancel_remaining: bool = False) -> None:
if cancel_remaining:
self._task_group.cancel_scope.cancel()

return DeprecatedAwaitable(self.stop)

async def _call_func(self, func: Callable, args: tuple, kwargs: Dict[str, Any],
future: Future) -> None:
def callback(f: Future) -> None:
Expand Down

0 comments on commit 2adff23

Please sign in to comment.