Skip to content

Added BlockingPortal.call_async() - #1343

Merged
agronholm merged 26 commits into
agronholm:masterfrom
davidbrochart:blocking-portal-call-async
Oct 31, 2026
Merged

agronholm merged 26 commits into
agronholm:masterfrom
davidbrochart:blocking-portal-call-async

Conversation

@davidbrochart

Copy link
Copy Markdown
Collaborator

NOTE Erasing or replacing the contents of this template will result in your pull
request being summarily closed without consideration!

Changes

Fixes #1342

Added BlockingPortal.call_async() to let one event loop asynchronously call into a portal running in another thread, without occupying an intermediary worker thread. The implementation supports asyncio and Trio, including cross backend calls, and propagates results, exceptions, context variables, and cancellation.

Checklist

If this is a user-facing code change, like a bugfix or a new feature, please ensure that
you've fulfilled the following conditions (where applicable):

  • You've added tests (in tests/) which would fail without your patch
  • You've updated the documentation (in docs/), in case of behavior changes or new
    features
  • You've added a new changelog entry (in docs/versionhistory.rst).

If this is a trivial change, like a typo fix or a code reformatting, then you can ignore
these instructions.

Updating the changelog

If there are no entries after the last release, use **UNRELEASED** as the version.
If, say, your patch fixes issue #123, the entry should look like this:

- Fix big bad boo-boo in task groups
  (`#123 <https://github.com/agronholm/anyio/issues/123>`_; PR by @yourgithubaccount)

If there's no issue linked, just link to your pull request instead by updating the
changelog after you've created the PR.

Comment thread src/anyio/_backends/_trio.py Resolved
@agronholm agronholm added this to the 4.16.0 milestone Oct 20, 2026
Comment thread src/anyio/from_thread.py Resolved
Comment thread src/anyio/from_thread.py Resolved
Comment thread src/anyio/from_thread.py Resolved
Comment thread docs/threads.rst Resolved
Comment thread src/anyio/_backends/_asyncio.py Resolved

@erlend-aasland erlend-aasland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A couple of comments on the docs (I'll leave the code changes in the hands of the domain experts already involved here).

Comment thread docs/threads.rst Resolved
Comment thread docs/threads.rst Resolved
agronholm and others added 2 commits October 30, 2026 10:14
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>

@agronholm agronholm left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think it's fine. I'd add an explanatory comment where we swallow RunFinishedError to avoid later confusion.

Comment thread src/anyio/from_thread.py Resolved
@agronholm
agronholm merged commit 02ff4f8 into agronholm:master Oct 31, 2026
20 checks passed
@davidbrochart
davidbrochart deleted the blocking-portal-call-async branch October 31, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an async interface for calling into an event loop running in another thread

4 participants