[Python-ideas] More general "for" loop handling

Joseph Martinot-Lagarde joseph.martinot-lagarde at m4x.org
Fri May 1 17:52:32 CEST 2015


Le 01/05/2015 02:35, Steven D'Aprano a écrit :
>
> If you still wish to argue for this, one thing which may help your case
> is if you can identify other programming languages that have already
> done something similar.
>
>
Cython has prange. It replaces range() in the for loop but runs the loop 
body in parallel using openmp:

from cython.parallel import prange

cdef int func(Py_ssize_t n):
     cdef Py_ssize_t i

     for i in prange(n, nogil=True):
         if i == 8:
             with gil:
                 raise Exception()
         elif i == 4:
             break
         elif i == 2:
             return i

This is an example from the cython documentation: 
http://docs.cython.org/src/userguide/parallelism.html

Joseph



More information about the Python-ideas mailing list