You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
but I want this to be a "harder" timeout, meaning that I want to move on after about 5-6 seconds. I know about abandon_on_cancel from to_thread.run_sync, but is there anything like that for async functions? I can't call to_thread.run_sync for every function in my function.
Maybe my design is broken is some way I don't see now, so I will ask more generally: Is there a way to actually cancel a running async task in trio? How would you implement such a timeout functionality?
The text was updated successfully, but these errors were encountered:
You’ll need to make those sync functions async, and ensure they await regularly - if you don’t need to do anything, just use trio.sleep(0). The way trio cancellation works is that all async Trio functions check for cancellation first, and if so raise an exception which is caught by the with block. So you just need to repeatedly check that.
With run_sync, that doesn’t actually cancel anything because you can’t arbitrarily stop a thread. Instead it just leaves it to keep running and ignores the result. As of the latest version, you can call trio.from_thread.check_cancelled() to check if the thead has been abandoned, and raise an exception to quit in that case. So that would also work.
Hi! First, I really like working with the library! Thanks for everything.
I want to implement a
timeout
mechanism for some of my functions. Something likebut I want this to be a "harder" timeout, meaning that I want to move on after about 5-6 seconds. I know about
abandon_on_cancel
fromto_thread.run_sync
, but is there anything like that for async functions? I can't callto_thread.run_sync
for every function in my function.Maybe my design is broken is some way I don't see now, so I will ask more generally: Is there a way to actually cancel a running async task in trio? How would you implement such a timeout functionality?
The text was updated successfully, but these errors were encountered: