[Python-Dev] Obtaining stack-frames from co-routine objects

Nick Coghlan ncoghlan at gmail.com
Sun Jun 14 03:05:36 CEST 2015


On 14 Jun 2015 03:35, "Guido van Rossum" <guido at python.org> wrote:
>
> On Sat, Jun 13, 2015 at 9:21 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> From a learnability perspective, there's also nothing about an
>> "f_stack" attribute that says "you can use this to find out where a
>> generator or coroutine has delegated control", while attributes like
>> "gi_delegate" or "cr_delegate" would be more self-explanatory.
>
> Stack frame objects are kind of expensive and I would hate to add an
extra pointer to every frame just to support this functionality. Perhaps we
could have a flag though that says whether the top of the stack is in fact
the generator object on which we're waiting in a yield-from? This flag
could perhaps sit next to f_executing (also note that this new flag is
mutually exclusive with f_executing). We could then easily provide a new
method or property on the frame object that returns the desired generator
if the flag is set or None if the flag is not set -- other Python
implementations could choose to implement this differently.

Fortunately, we can expose this control flow delegation info through the
generator-iterator and coroutine object APIs, rather than needing to do it
directly on the frame.

I'd missed that it could be done without *any* new C level state though - I
now think Ben's right that we should be able to just expose the delegation
lookup from the resumption logic itself as a calculated property.

Cheers,
Nick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150614/1de07516/attachment.html>


More information about the Python-Dev mailing list