[Python-Dev] PEP 492: What is the real goal?
ethan at stoneleaf.us
Fri May 1 21:24:04 CEST 2015
On 05/01, Guido van Rossum wrote:
> On Fri, May 1, 2015 at 11:26 AM, Jim J. Jewett <jimjjewett at gmail.com> wrote:
>> So does this mean that yield should NOT be used just to yield control
>> if a task isn't blocked? (e.g., if its next step is likely to be
>> long, or low priority.) Or even that it wouldn't be considered a
>> co-routine in the python sense?
> 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.
So when a generator is used as an iterator, yield and yield from are used
to produce the actual working values...
But when a generator is used as a coroutine, yield (and yield from?) are
used to provide context about when they should be run again?
More information about the Python-Dev