Proposed new syntax

Pavol Lisy pavol.lisy at gmail.com
Tue Aug 22 09:07:36 EDT 2017


On 8/21/17, Chris Angelico <rosuav at gmail.com> wrote:
> On Mon, Aug 21, 2017 at 12:19 PM, MRAB <python at mrabarnett.plus.com> wrote:
>> On 2017-08-21 03:00, Steve D'Aprano wrote:
>>>
>>> On Fri, 18 Aug 2017 04:55 pm, Marko Rauhamaa wrote:
>>>
>>>> Is a Python implementation
>>>> allowed to parallelize or otherwise reorder the evaluation loop?
>>>
>>>
>>> No.
>>>
>> [snip]
>>
>> Well, I suppose an implementation _could_ parallelise, or whatever,
>> _provided that_ it gave the same result.
>
> In other words, it's allowed to parallelise, just as long as
> everything happens sequentially. With arbitrary expressions, one of
> them could affect another easily.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>


import multiprocessing
def square(param):
    ret = param[0] * param[0]
    param[1].put("%d is done" % param[0])
    return ret

pool = multiprocessing.Pool(processes=3)
m = multiprocessing.Manager()
q = m.Queue()
squares = pool.map(square, ((i, q) for i in range(10)))
print(squares)  # ordered
print([q.get() for i in range(q.qsize())])  # unordered

[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
['0 is done', '2 is done', '1 is done', '3 is done', '4 is done', '5
is done', '7 is done', '6 is done', '8 is done', '9 is done']

You could collect result sequentially (ordered) but calculate it
parallel (unordered).



More information about the Python-list mailing list