Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Creating Event when in from_thread.run_sync() context #500

Closed
tapetersen opened this issue Nov 14, 2022 · 1 comment
Closed

Creating Event when in from_thread.run_sync() context #500

tapetersen opened this issue Nov 14, 2022 · 1 comment

Comments

@tapetersen
Copy link
Contributor

When using to_thread.run_sync and then calling back again to the event loop with from_thread.run_sync I can't create an anyio.Event since sniffio fails to detect the running loop (no current_task is set in asyncio which of course is kindof true).

Reproduced in a gist here https://gist.github.com/tapetersen/e85a808f0bba7dd396fa68eafb41012d

@tapetersen tapetersen changed the title Creating when in from_thread.run_sync() context Creating Event when in from_thread.run_sync() context Nov 14, 2022
@tapetersen
Copy link
Contributor Author

This is not critical for us and can be worked around by creating asyncio.Event objects directly (not ideal to tie to backend but ok in our case) or by making the function async which I would want to avoid since it doesn't really yield to the event loop or await anything.

from_thread here is really just used to ensure thread safety since the method modifies some other state that isn't explicitly locked but relies on only being modified by the main thread running the loop.

I don't know about triobut at least in asyncio it has been ok to create Event objects outside async contexts and also in different event loops as they don't actually bind to a loop until waited upon since 3.9

Repository owner locked and limited conversation to collaborators Nov 16, 2022
@agronholm agronholm converted this issue into discussion #501 Nov 16, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant