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
coroutine wrapper reentrancy #68530
Comments
Consider following piece of code: async def foo():
return 'spam'
def wrapper(coro):
async def wrap(coro):
print('before')
try:
return await coro
finally:
print('after')
return wrap(coro)
import sys
sys.set_coroutine_wrapper(wrapper)
print(foo().send(None)) Current python will crash with a "RuntimeError: maximum recursion depth exceeded", because "wrap" is itself a coroutine, so ceval will call "wrapper" recursively. There are three options here:
The attached patch implements (2). It also makes PyEval*CoroWrapper methods private. I, myself, vote for option 2. |
On Sun, May 31, 2015 at 9:11 PM, Yury Selivanov <report@bugs.python.org> wrote:
If it's good enough for other programmer-induced infinite recursion |
Changing the title back. :) |
Because it's highly non-obvious, it took me a while to understand what's *actually* going on. |
This is a bit off topic, but why did my reply to Yuri's ticket by email change the title? I didn't mess with the subject in my mail. |
@Skip, because roundup will change the title to the subject of the email and the title had been changed after the message to which you replied. |
Making sure I'm following the issue correctly here:
I like the idea in principle, I don't like the error message in the current patch (since it only makes sense if you already understand the chain of reasoning above). While it's a little verbose, I suggest an error like: "Coroutine wrapper %r attempted to recursively wrap %r", passing in the currently registered coroutine wrapper, and the code object we're attempting to wrap, respectively. The latter repr gives the name, filename and line number of the offending code object, while the former should give the qualname of the registered wrapper. The docs for set_coroutine_wrapper() should also be tweaked to note the constraint that the wrapper function cannot itself define new asynchronous functions (neither directly nor indirectly). |
Thanks, Nick! I'll commit the patch with your error message (it's much better!) |
New changeset 19d613c2cd5f by Yury Selivanov in branch '3.5': New changeset 8a6db1679a23 by Yury Selivanov in branch 'default': |
New changeset d11cb1218489 by Yury Selivanov in branch '3.5': New changeset b83fbc13ae1e by Yury Selivanov in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: