[Python-Dev] [PEP 3148] futures - execute computations asynchronously
Greg Ewing
greg.ewing at canterbury.ac.nz
Mon Mar 8 22:39:14 CET 2010
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()
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.
--
Greg
More information about the Python-Dev
mailing list