Message244569
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:
1. Leave things as is;
2. Add a flag in tstate that coroutine_wrapper is executing, and raise a RuntimeError if it's reentering;
3. Add a flag in tstate (see 2) and skip wrapping when reentering (i.e. return what was passed to the wrapper).
The attached patch implements (2). It also makes PyEval*CoroWrapper methods private.
I, myself, vote for option 2. |
|
Date |
User |
Action |
Args |
2015-06-01 02:11:34 | yselivanov | set | recipients:
+ yselivanov, gvanrossum, ncoghlan, vstinner |
2015-06-01 02:11:34 | yselivanov | set | messageid: <1433124694.62.0.501554700121.issue24342@psf.upfronthosting.co.za> |
2015-06-01 02:11:34 | yselivanov | link | issue24342 messages |
2015-06-01 02:11:33 | yselivanov | create | |
|