<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, May 1, 2015 at 8:52 AM, Joseph Martinot-Lagarde <span dir="ltr"><<a href="mailto:joseph.martinot-lagarde@m4x.org" target="_blank">joseph.martinot-lagarde@m4x.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Le 01/05/2015 02:35, Steven D'Aprano a écrit :<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
If you still wish to argue for this, one thing which may help your case<br>
is if you can identify other programming languages that have already<br>
done something similar.<br>
<br>
<br>
</blockquote></span>
Cython has prange. It replaces range() in the for loop but runs the loop body in parallel using openmp:<br>
<br>
from cython.parallel import prange<br>
<br>
cdef int func(Py_ssize_t n):<br>
    cdef Py_ssize_t i<br>
<br>
    for i in prange(n, nogil=True):<br>
        if i == 8:<br>
            with gil:<br>
                raise Exception()<br>
        elif i == 4:<br>
            break<br>
        elif i == 2:<br>
            return i<br>
<br>
This is an example from the cython documentation: <a href="http://docs.cython.org/src/userguide/parallelism.html" target="_blank">http://docs.cython.org/src/userguide/parallelism.html</a><span class="HOEnZb"><font color="#888888"></font></span><br></blockquote></div><br></div><div class="gmail_extra">Interesting. I'm trying to imagine how this could be implemented in CPython by turning the for-loop body into a coroutine. It would be a complicated transformation because of the interaction with local variables in the code surrounding the for-loop. Perhaps the compiler could mark all such variables as implicitly nonlocal. The Cython example also shows other interesting issues -- what should return or break do?<br><br></div><div class="gmail_extra">In any case, I don't want this idea to distract the PEP 492 discussion -- it's a much thornier problem, and maybe coroutine concurrency isn't what we should be after here -- the use cases here seem to be true (GIL-free) parallelism. I'm imagining that pyparallel has already solved this (if it has solved anything :-).<br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>