-
-
Notifications
You must be signed in to change notification settings - Fork 748
Overwrite worker plugins #5248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overwrite worker plugins #5248
Conversation
This changes behavior for WorkerPlugins to overwrite the previous plugin if there is a colliding name.
|
I'm going to go ahead and merge this. I'm happy to revisit it at any point in the future if folks have concerns. This unifies behavior across scheduler/worker/nanny plugins with respect to overwriting by name. |
|
Thanks @mrocklin. Just for reference, it was already the plan the plan to update this behavior and was implemented over in #5142 |
@mrocklin, @jrbourbeau, @crusaderky I have code that needs the plugin to be registered exactly once per worker and any subsequent registration will make the system work in unexpected ways. For example the code below needs to create the asyncio loop only the first time the registration happens. import asyncio
loop: Optional[asyncio.AbstractEventLoop] = None
class InitWorker(distributed.WorkerPlugin):
# Prevent the plugin from being registered twice on the same worker
name = "Init"
def setup(self, worker) -> None:
assert not loop
new_loop = asyncio.new_event_loop()
future = asyncio.run_coroutine_threadsafe(init_app(), new_loop)
future.result()
assert loop is new_loop
def teardown(self, worker) -> None:
assert loop
loop.call_soon_threadsafe(loop.stop)I tried to change my setup method to something like this, but this does not work def setup(self, worker) -> None:
# plugin has already been registered by worker
if self.name in worker.plugins:
return
assert not loop
new_loop = asyncio.new_event_loop()
future = asyncio.run_coroutine_threadsafe(init_app(), new_loop)
future.result()
assert loop is new_loopIs there a work around to get the previous behaviour? Thank you Also as a side note, some of the pydoc may not be uptodate distributed/distributed/client.py Lines 4274 to 4276 in 1721d62
|
You could subclass Worker and override Worker.register_worker_plugin. Then you would start workers with P.S. adding a comment to a closed PR is generally a bad idea in terms of visibility. |
|
alternatively, you could do class InitWorker(distributed.WorkerPlugin):
...
async def register(self, dask_scheduler):
if self.name not in dask_scheduler.worker_plugins:
return await dask_scheduler.register_worker_plugin(plugin=self, name=self.name)
client.run_on_scheduler(InitWorker().register) |
|
Thank you @crusaderky,
did you mean subclass Worker.plugin_add?
I have opened a new issue |
This changes behavior for WorkerPlugins to overwrite the previous plugin
if there is a colliding name.
black distributed/flake8 distributed/isort distributed