![](https://secure.gravatar.com/avatar/b027277871dcb82229b506bd2df35b6c.jpg?s=120&d=mm&r=g)
Le 03/05/2015 23:52, Joseph Martinot-Lagarde a écrit :
Le 02/05/2015 18:16, Andrew Barnert via Python-ideas a écrit :
On May 1, 2015, at 08:52, Joseph Martinot-Lagarde <joseph.martinot-lagarde@m4x.org> wrote:
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:
I think that's pretty good evidence that this proposal (I meant the syntax for loop modifiers, not "some way to do loops in parallel would be nice") isn't needed. What OpenMP has to do with loop modifier syntax, Cython can do with just a special iterator in normal Python syntax.
Cython uses python syntax but the behavior is different. This is especially obvious seeing how break and return are managed, where the difference in not only in the iterator.
Sorry, ignore my last email. I agree that no new *syntax* is needed.
Of course that doesn't guarantee that something similar to prange could be built for Python 3.5's Pool, Executor, etc. types without changes, but if even if it can't, a change to the iterator protocol to make prange bulldable doesn't seem as disruptive as a change to the basic syntax of the for loop. (Unless there just is no reasonable change to the protocol that could work.)
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
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/