<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Aug 28, 2017 at 6:07 PM, Nathaniel Smith <span dir="ltr"><<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>></span> wrote:<span class=""></span><br><span class=""></span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
</span>The important difference between generators/coroutines and normal<br>
function calls is that with normal function calls, the link between<br>
the caller and callee is fixed for the entire lifetime of the inner<br>
frame, so there's no way for the context to shift under your feet. If<br>
all we had were normal function calls, then (green-) thread locals<br>
using the save/restore trick would be enough to handle all the use<br>
cases above -- it's only for generators/coroutines where the<br>
save/restore trick breaks down. This means that pushing/popping LCs<br>
when crossing into/out of a generator frame is the minimum needed to<br>
get the desired semantics, and it keeps the LC stack small (important<br>
since lookups can be O(n) in the worst case), and it minimizes the<br>
backcompat breakage for operations like decimal.setcontext() where<br>
people *do* expect to call it in a subroutine and have the effects be<br>
visible in the caller.<span class="im HOEnZb"></span><br></blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">I like this way of looking at things. Does this have any bearing on asyncio.Task? To me those look more like threads than like generators. Or possibly they should inherit the lookup chain from the point when the Task was created, but not be affected at all by the lookup chain in place when they are executed. FWIW we *could* have a policy that OS threads also inherit the lookup chain from their creator, but I doubt that's going to fly with backwards compatibility.</div><div class="gmail_extra"><br></div><div class="gmail_extra">I guess my general (hurried, sorry) view is that we're at a good point where we have a small number of mechanisms but are still debating policies on how those mechanisms should be used. (The basic mechanism is chained lookup and the policies are about how the chains are fit together for various language/library constructs.)<br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>