Skip to content

Commit 2adff23

Browse files
committed
make BlockingPortal.stop sync
1 parent 5591099 commit 2adff23

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/anyio/from_thread.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from warnings import warn
1010

1111
from ._core import _eventloop
12+
from ._core._compat import DeprecatedAwaitable
1213
from ._core._eventloop import get_asynclib, get_cancelled_exc_class, threadlocals
1314
from ._core._synchronization import Event
1415
from ._core._tasks import CancelScope, create_task_group
@@ -130,7 +131,7 @@ async def __aenter__(self) -> 'BlockingPortal':
130131
async def __aexit__(self, exc_type: Optional[Type[BaseException]],
131132
exc_val: Optional[BaseException],
132133
exc_tb: Optional[TracebackType]) -> Optional[bool]:
133-
await self.stop()
134+
self.stop()
134135
return await self._task_group.__aexit__(exc_type, exc_val, exc_tb)
135136

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

146-
async def stop(self, cancel_remaining: bool = False) -> None:
147+
def stop(self, cancel_remaining: bool = False) -> DeprecatedAwaitable:
147148
"""
148149
Signal the portal to shut down.
149150
@@ -159,6 +160,8 @@ async def stop(self, cancel_remaining: bool = False) -> None:
159160
if cancel_remaining:
160161
self._task_group.cancel_scope.cancel()
161162

163+
return DeprecatedAwaitable(self.stop)
164+
162165
async def _call_func(self, func: Callable, args: tuple, kwargs: Dict[str, Any],
163166
future: Future) -> None:
164167
def callback(f: Future) -> None:

0 commit comments

Comments
 (0)