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
I have searched the existing issues and didn't find my bug already reported there
I have checked that my bug is still present in the latest release
AnyIO version
4.3.0
Python version
3.10.13; 3.12.1
What happened?
Run a cancel scope within another cancel scope. Cancel the inner one then await something so that a cancellation exception is raised, but during handling also cancel the outer one (but do not call any more unshielded async functions before the end of the inner block). With the asyncio backend, the inner block will swallow the cancellation exception, allowing the outer block to continue running (until the next unshielded await in it), while the Trio backend will propagate the exception right out to the end of the outer block
importanyioasyncdefcancel_check():
withanyio.CancelScope() asouter_scope:
withanyio.CancelScope() asinner_scope:
awaitanyio.sleep(0.1)
inner_scope.cancel()
print("inner cancelled")
try:
awaitanyio.sleep(0.1)
finally:
outer_scope.cancel()
print("outer cancelled")
print("should not be here inner")
print("should not be here outer")
print("all done")
anyio.run(cancel_check, backend="trio")
Output with Trio backend:
inner cancelled
outer cancelled
all done
Output with asyncio backend:
inner cancelled
outer cancelled
should not be here outer
all done
The text was updated successfully, but these errors were encountered:
I tried fixing this by raising a new CancelledError from CancelScope.__exit__(), but that interacted poorly with task groups, as they're not prepared to handle exceptions falling out of that method (timeouts in taskgroup.cancel_scope are not a thing).
Things to check first
I have searched the existing issues and didn't find my bug already reported there
I have checked that my bug is still present in the latest release
AnyIO version
4.3.0
Python version
3.10.13; 3.12.1
What happened?
Run a cancel scope within another cancel scope. Cancel the inner one then
await
something so that a cancellation exception is raised, but during handling also cancel the outer one (but do not call any more unshielded async functions before the end of the inner block). With the asyncio backend, the inner block will swallow the cancellation exception, allowing the outer block to continue running (until the next unshieldedawait
in it), while the Trio backend will propagate the exception right out to the end of the outer blockBy the way, the Trio docs give the impression that it is meant to work the same way as the asyncio backend does. (See discussion on Trio Discourse: Do
Cancelled
exceptions “know” which block they belong to?)How can we reproduce the bug?
Output with Trio backend:
Output with asyncio backend:
The text was updated successfully, but these errors were encountered: