[Python-Dev] [PEP 3148] futures - execute computations asynchronously

Terry Reedy tjreedy at udel.edu
Tue Mar 9 06:14:28 CET 2010


On 3/8/2010 4:39 PM, Greg Ewing wrote:
> Terry Reedy wrote:
>> Looking more close, I gather that the prime results will be printed
>> 'in order' (waiting on each even if others are done) while the url
>> results will be printed 'as available'.
>
> Seems to me that if you care about the order of the results,
> you should be able to just wait for each result separately
> in the order you want them. Something like
>
> task1 = start_task(proc1)
> task2 = start_task(proc2)
> task3 = start_task(proc3)
> result1 = task1.wait_for_result()
> result2 = task2.wait_for_result()
> result3 = task3.wait_for_result()

*If* I understand the first example correctly, this is effectively what 
the first example does with two loops. But I was hoping for 
clarification and amplification in the PEP.
>
> This would also be a natural way to write things even if
> you don't care about the order, but you need all the results
> before proceeding. You're going to be held up until the
> longest-running task completes anyway, so it doesn't matter
> if some of them finish earlier and have to sit around
> waiting for you to collect the result.
>




More information about the Python-Dev mailing list