This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author yselivanov
Recipients gvanrossum, ncoghlan, vstinner, yselivanov
Date 2015-06-01.02:11:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1433124694.62.0.501554700121.issue24342@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-06-01 02:11:34yselivanovsetrecipients: + yselivanov, gvanrossum, ncoghlan, vstinner
2015-06-01 02:11:34yselivanovsetmessageid: <1433124694.62.0.501554700121.issue24342@psf.upfronthosting.co.za>
2015-06-01 02:11:34yselivanovlinkissue24342 messages
2015-06-01 02:11:33yselivanovcreate