用法:
class distributed.Client(address=None, loop=None, timeout='__no_default__', set_as_default=True, scheduler_file=None, security=None, asynchronous=False, name=None, heartbeat_interval=None, serializers=None, deserializers=None, extensions=[<class 'distributed.pubsub.PubSubClientExtension'>], direct_to_workers=None, connection_limit=512, **kwargs)
連接到 Dask 集群並向其提交計算
客戶端將用戶連接到 Dask 集群。它提供了一個圍繞函數和期貨的異步用戶接口。此類類似於
concurrent.futures
中的執行程序,但也允許在submit/map
調用中使用Future
對象。當客戶端被實例化時,它默認接管所有dask.compute
和dask.persist
調用。在不指定調度程序地址的情況下創建客戶端也很常見,例如
Client()
。在這種情況下,客戶端會在後台創建一個LocalCluster
並連接到它。在這種情況下,任何額外的關鍵字都會從客戶端傳遞到 LocalCluster。有關詳細信息,請參閱LocalCluster 文檔。- address: string, or Cluster:
這可以是
Scheduler
服務器的地址,例如字符串'127.0.0.1:8786'
或集群對象,例如LocalCluster()
- loop:
事件循環
- timeout: int:
初始連接到調度程序的超時持續時間
- set_as_default: bool (True):
將此客戶端用作全局 dask 調度程序
- scheduler_file: string (optional):
帶有調度程序信息的文件的路徑(如果可用)
- security: Security or bool, optional:
可選的安全信息。如果創建本地集群也可以傳入
True
,在這種情況下會自動創建臨時的 self-signed 憑據。- asynchronous: bool (False by default):
如果在 async/await 函數或 Tornado 中使用此客戶端,則設置為 True gen.coroutines 否則,對於正常使用,這應該保持為 False。
- name: string (optional):
為客戶端提供一個名稱,該名稱將包含在調度程序為與該客戶端相關的事務生成的日誌中
- heartbeat_interval: int (optional):
心跳到調度程序之間的時間(以毫秒為單位)
- serializers:
序列化對象時使用的可迭代方法。有關更多信息,請參見序列化。
- deserializers:
反序列化對象時使用的可迭代方法。有關更多信息,請參見序列化。
- extensions:列表
擴展名
- direct_to_workers: bool (optional):
是否直接連接到worker,或者要求調度器充當中介。
- connection_limit:int
連接池中一次維護的打開通信數
- **kwargs:
如果您不傳遞調度程序地址,客戶端將創建一個
LocalCluster
對象,並傳遞任何額外的關鍵字參數。
參數:
例子:
在初始化時提供集群的調度程序節點地址:
>>> client = Client('127.0.0.1:8786')
使用
submit
方法將單個計算發送到集群>>> a = client.submit(add, 1, 2) >>> b = client.submit(add, 10, 20)
繼續使用提交或映射結果來構建更大的計算
>>> c = client.submit(add, a, b)
使用
gather
方法收集結果。>>> client.gather(c) 33
您也可以不帶參數調用 Client 來創建自己的本地集群。
>>> client = Client() # makes your own local "cluster"
額外的關鍵字將直接傳遞給LocalCluster
>>> client = Client(n_workers=2, threads_per_worker=4)
相關用法
- Python distributed.Client.gather用法及代碼示例
- Python distributed.Client.ncores用法及代碼示例
- Python distributed.Client.retire_workers用法及代碼示例
- Python distributed.Client.unregister_worker_plugin用法及代碼示例
- Python distributed.Client.set_metadata用法及代碼示例
- Python distributed.Client.scheduler_info用法及代碼示例
- Python distributed.Client.submit用法及代碼示例
- Python distributed.Client.compute用法及代碼示例
- Python distributed.Client.nthreads用法及代碼示例
- Python distributed.Client.unpublish_dataset用法及代碼示例
- Python distributed.Client.start_ipython_scheduler用法及代碼示例
- Python distributed.Client.get用法及代碼示例
- Python distributed.Client.publish_dataset用法及代碼示例
- Python distributed.Client.who_has用法及代碼示例
- Python distributed.Client.get_versions用法及代碼示例
- Python distributed.Client.profile用法及代碼示例
- Python distributed.Client.run用法及代碼示例
- Python distributed.Client.register_worker_plugin用法及代碼示例
- Python distributed.Client.map用法及代碼示例
- Python distributed.Client.log_event用法及代碼示例
注:本文由純淨天空篩選整理自dask.org大神的英文原創作品 distributed.Client。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。