用法:
class distributed.as_completed(futures=None, loop=None, with_results=False, raise_errors=True)
按完成的順序返回期貨
這將返回一個迭代器,該迭代器按照它們完成的順序產生輸入的未來對象。在迭代器上調用
next
將阻塞,直到下一個未來完成,無論順序如何。此外,您還可以在計算期間使用
.add
方法向該對象添加更多期貨- futures: Collection of futures:
按照完成順序迭代的 Future 對象列表
- with_results: bool (False):
是否等待並包括期貨結果;在這種情況下
as_completed
產生一個元組 (future, result)- raise_errors: bool (True):
當未來的結果引發異常時我們是否應該引發;僅在
with_results=True
時影響行為。
參數:
例子:
>>> x, y, z = client.map(inc, [1, 2, 3]) >>> for future in as_completed([x, y, z]): ... print(future.result()) 3 2 4
在計算期間添加更多期貨
>>> x, y, z = client.map(inc, [1, 2, 3]) >>> ac = as_completed([x, y, z]) >>> for future in ac: ... print(future.result()) ... if random.random() < 0.5: ... ac.add(c.submit(double, future)) 4 2 8 3 6 12 24
也可以選擇等到結果收集完畢
>>> ac = as_completed([x, y, z], with_results=True) >>> for future, result in ac: ... print(result) 2 4 3
相關用法
- Python distributed.as_completed.batches用法及代碼示例
- Python distributed.as_completed.next_batch用法及代碼示例
- Python distributed.active_memory_manager.ActiveMemoryManagerPolicy.run用法及代碼示例
- Python distributed.protocol.serialize.register_generic用法及代碼示例
- Python distributed.Client.gather用法及代碼示例
- Python distributed.recreate_tasks.ReplayTaskClient.recreate_task_locally用法及代碼示例
- Python distributed.diagnostics.plugin.SchedulerPlugin用法及代碼示例
- Python distributed.Client.ncores用法及代碼示例
- Python distributed.Client.retire_workers用法及代碼示例
- Python distributed.Client.unregister_worker_plugin用法及代碼示例
- Python distributed.fire_and_forget用法及代碼示例
- Python distributed.Client.set_metadata用法及代碼示例
- Python distributed.Client.scheduler_info用法及代碼示例
- Python distributed.Client.submit用法及代碼示例
- Python distributed.Client.compute用法及代碼示例
- Python distributed.SpecCluster.scale用法及代碼示例
- Python distributed.get_worker用法及代碼示例
- Python distributed.SpecCluster.scale_up用法及代碼示例
- Python distributed.Client.nthreads用法及代碼示例
- Python distributed.comm.resolve_address用法及代碼示例
注:本文由純淨天空篩選整理自dask.org大神的英文原創作品 distributed.as_completed。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。