Skip to content

Pass backend_options to Trio - #1161

Merged
agronholm merged 1 commit into
agronholm:masterfrom
Zac-HD:fix-trio-backend-options
Jun 2, 2026
Merged

agronholm merged 1 commit into
agronholm:masterfrom
Zac-HD:fix-trio-backend-options

Conversation

@Zac-HD

@Zac-HD Zac-HD commented Jun 1, 2026 •

Copy link
Copy Markdown
Collaborator

Changes

In AnyIO 3.x the module-level run = trio.run was invoked as asynclib.run(func, *args, **backend_options), but since 4.0's AsyncBackend refactor anyio.run(..., backend="trio", backend_options={...}) silently discards the backend_options.

We still document trio backend_options as forwarded to trio.run, with restrict_keyboard_interrupt_to_checkpoints as an example, so this PR restores support in the obvious way.

A minimal motivating repro:

import time, trio, trio.testing
from fastapi import FastAPI
from fastapi.testclient import TestClient

app = FastAPI()
@app.get("/s")
async def s():
    await trio.sleep(5)
    return {"t": trio.current_time()}

c = TestClient(app, backend="trio",
               backend_options={"clock": trio.testing.MockClock(autojump_threshold=0)})
t0 = time.monotonic()
c.get("/s")
print(f"wall={time.monotonic()-t0:.2f}s")  # 5.01s — clock never reached trio.run

Fixes #1162.

Checklist

  • You've added tests (in tests/) which would fail without your patch
  • You've updated the documentation (n/a; restoring already-documented behavior)
  • You've added a new changelog entry (in docs/versionhistory.rst).

@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.

LGTM.

@agronholm
agronholm merged commit d858f82 into agronholm:master Jun 2, 2026
18 checks passed
@Zac-HD
Zac-HD deleted the fix-trio-backend-options branch June 2, 2026 21:45
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.

In anyio.run, backend_options= are not passed to trio.

2 participants