<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, May 1, 2015 at 11:26 AM, Jim J. Jewett <span dir="ltr"><<a href="mailto:jimjjewett@gmail.com" target="_blank">jimjjewett@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, Apr 30, 2015 at 3:32 PM, Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:<br>
<br>
(me:)<br>
>> A badly worded attempt to say<br>
>> Normal generator:  yield (as opposed to return) means<br>
>> that the function isn't done, and there may be more<br>
>> things to return later.<br>
<span class=""><br>
>> but an asynchronous (PEP492) coroutine is primarily saying:<br>
<br>
>>      "This might take a while, go ahead and do something else<br>
>> meanwhile."<br>
<br>
</span>(Yuri:) Correct.<br>
<br>
(Guido:)> Actually that's not even wrong. When using generators as<br>
<span class="">coroutines, PEP 342<br>
> style, "yield" means "I am blocked waiting for a result that the I/O<br>
> multiplexer is eventually going to produce".<br>
<br>
</span>So does this mean that yield should NOT be used just to yield control<br>
if a task isn't blocked?  (e.g., if its next step is likely to be<br>
long, or low priority.)  Or even that it wouldn't be considered a<br>
co-routine in the python sense?<br></blockquote><div><br></div><div>I'm not sure what you're talking about. Does "next step" refer to something in the current stack frame or something that you're calling? None of the current uses of "yield" (the keyword) in Python are good for lowering priority of something. It's not just the GIL, it's that coroutines (by whatever name) are still single-threaded. If you have something long-running CPU-intensive you should probably run it in a background thread (or process) e.g. using an executor.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If this is really just about avoiding busy-wait on network IO, then<br>
coroutine is way too broad a term, and I'm uncomfortable restricting a<br>
new keyword (async or await) to what is essentially a Domain Specific<br>
Language.<br></blockquote><div><br></div><div>The common use case is network I/O. But it's quite possible to integrate coroutines with a UI event loop.<br></div><div> </div></div>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>