Incorrect Context in corotine's except and finally blocks
#93740
Labels
type-bug
An unexpected behavior, bug, or error


Bug report
Now we have the following code to show what happen:
If I left it run to the end, the result will as expected:
But if I interrupt it while running, it turns to:
Obviously, the
ctx.get()inexceptandfinallyblocks didn't work as expected.What's more, this not only happen by KeyboardInterrupt, but also other operations that will triger
exceptorfinallyblock, such asgarbage collect.As it is hard to trigger
gc, so I can't give a minimal case, but a real case https://github.com/GraiaProject/BroadcastControl/blob/6a4a13e3531109bcb82dd4b306e7498d2bff9b0b/src/graia/broadcast/__init__.py#L207:The "free-flying" task is collected by
gc, and triggerfinally. Butctx.reset()raised a ValueError, caused the token "was created in a different Context".Though I didn't test, I suppose any exception or other else that trigger
exceptorfinallyoutside a corotine will suffer from this problem.Your environment
The text was updated successfully, but these errors were encountered: