-
-
Notifications
You must be signed in to change notification settings - Fork 352
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
Add an @trio.not_in_async_task
decorator, to error instead of stalling
#2757
Comments
Perhaps the more fundamental primitive here is
The private implementation could check for the existence of (There is a subtle difference between checking for |
I think this would be helpful. Given that debugging tools seem to be in |
I would agree that |
What's the expected behavior in guest runs? (maybe we should just tell people "use |
In a guest run, as well as some other places like abort_fn calls and some instrument calls, you are in a Trio run ( I attempted to make sniffio explicit about this using python-trio/sniffio#38 and the linked python-trio/sniffio#39 but it was never reviewed. I think Trio should probably provide both |
In a large codebase, you're going to have some functions which are slow, and so you don't want them to be called from an async task (without using
trio.to_thread.run_sync(slow_fn)
, anyway).flake8-trio
'sTRIO200
error can help find direct calls, but indirect calls are really hard to find via static analysis.As I mentioned in my PyCon talk, and work we've implemented a decorator to mark sync functions which can be called in a sync context, but must be delegated to a worker thread instead of being called in an async context - no matter how many sync functions are in the intermediate call chain. Simple implementation:
Should we include this in
trio
itself? I've certainly found the pattern useful, and upstreaming it would encourage wider use of the pattern. On the other hand it's not entirely clear where this would fit, and it's neither hard to implement nor something which benefits much from standardization.The text was updated successfully, but these errors were encountered: