用法:
register_worker_plugin(plugin=None, name=None, nanny=None, **kwargs)為所有當前和未來的工作人員注冊一個生命周期工作人員插件。
這會注冊一個新對象來處理此集群中工作人員的設置、任務狀態轉換和拆卸。該插件將在所有當前連接的工作人員上實例化自己。它也將在未來連接的任何工作人員上運行。
該插件可能包括方法
setup,teardown,transition和release_key。有關接口和文檔字符串,請參閱dask.distributed.WorkerPlugin類或下麵的示例。它必須可以使用 pickle 或 cloudpickle 模塊進行序列化。如果插件有
name屬性,或者如果使用了name=關鍵字,那麽這將控製冪等性。如果具有該名稱的插件已經注冊,那麽它將被刪除並替換為新插件。對於插件的替代品,您可能還希望查看預加載腳本。
- plugin:WorkerPlugin 或 NannyPlugin
要注冊的 WorkerPlugin 或 NannyPlugin 實例。
- name:str,可選
插件的名稱。注冊同名插件將無效。如果插件沒有名稱屬性,則使用隨機名稱。
- nanny:布爾型,可選
是否向工人或保姆注冊插件。
- **kwargs:可選的
已棄用;如果您將類作為插件傳遞,而不是類實例,則該類將使用任何額外的關鍵字參數進行實例化。
參數:
例子:
>>> class MyPlugin(WorkerPlugin): ... def __init__(self, *args, **kwargs): ... pass # the constructor is up to you ... def setup(self, worker: dask.distributed.Worker): ... pass ... def teardown(self, worker: dask.distributed.Worker): ... pass ... def transition(self, key: str, start: str, finish: str, ... **kwargs): ... pass ... def release_key(self, key: str, state: str, cause: str | None, reason: None, report: bool): ... pass>>> plugin = MyPlugin(1, 2, 3) >>> client.register_worker_plugin(plugin)您可以使用
get_worker函數訪問插件>>> client.register_worker_plugin(other_plugin, name='my-plugin') >>> def f(): ... worker = get_worker() ... plugin = worker.plugins['my-plugin'] ... return plugin.my_state>>> future = client.run(f)
相關用法
- Python distributed.Client.retire_workers用法及代碼示例
- Python distributed.Client.replicate用法及代碼示例
- Python distributed.Client.run用法及代碼示例
- Python distributed.Client.run_on_scheduler用法及代碼示例
- Python distributed.Client.gather用法及代碼示例
- Python distributed.Client.ncores用法及代碼示例
- 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.map用法及代碼示例
注:本文由純淨天空篩選整理自dask.org大神的英文原創作品 distributed.Client.register_worker_plugin。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
