Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create anyio.Event using a blocking portal #2459

Merged
merged 3 commits into from
Feb 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion starlette/testclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import typing
import warnings
from concurrent.futures import Future
from functools import cached_property
from types import GeneratorType
from urllib.parse import unquote, urljoin

Expand Down Expand Up @@ -95,7 +96,6 @@ def __init__(
def __enter__(self) -> WebSocketTestSession:
self.exit_stack = contextlib.ExitStack()
self.portal = self.exit_stack.enter_context(self.portal_factory())
self.should_close = anyio.Event()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyio.Event cannot be instantiated on non-async context before anyio 4.2.0.


try:
_: Future[None] = self.portal.start_task_soon(self._run)
Expand All @@ -109,6 +109,10 @@ def __enter__(self) -> WebSocketTestSession:
self.extra_headers = message.get("headers", None)
return self

@cached_property
def should_close(self) -> anyio.Event:
return anyio.Event()

async def _notify_close(self) -> None:
self.should_close.set()

Expand Down