用法:
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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
