Re-using existing event loop in BlockingPortal / compatibility with pytest-asyncio
#883
Unanswered
tuukkamustonen
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
No, it's not possible to pass an existing event loop to it. When you create and enter a |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible to pass existing event-loop to
BlockingPortal?Starlette/FastAPI
TestClientuses blocking portal underneath, and as I've understood it spawns a thread and runs an event loop of its own there.So if you use something like
pytest-asynciowhich creates the event loop, initialize an async resource in an async test or fixture, then pass that it the app, it gets run in a different event loop and might raise and error.As an example,
psycopgdoesn't raise error, butasyncpgdoes. See sqlalchemy/sqlalchemy#12211 (reply in thread). In general, switching the event loop is probably not a good idea / guaranteed to work, if the resource maintains state like connections etc.So... is it possible to use
BlockingPortalwith existing (asyncio) event loop (or should I overwrite theTestClientto use something likeloop.run_until_complete()instead)?Beta Was this translation helpful? Give feedback.
All reactions