New submission from Yury Selivanov: 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. ---------- assignee: yselivanov components: Interpreter Core files: coro_wrapper.patch keywords: patch messages: 244569 nosy: gvanrossum, haypo, ncoghlan, yselivanov priority: normal severity: normal status: open title: coroutine wrapper recursion versions: Python 3.5, Python 3.6 Added file: http://bugs.python.org/file39578/coro_wrapper.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue24342> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com