Prevent overwrite worker plugins
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 778
- Avg merge
- 2h 50m
- Merged PRs (30d)
- 3
Description
Up to distributed version 2021.8, it was possible to add a worker plugin with the same name as an already registered plugin and this would make no difference as the registered plugin is not overwritten.
However, since this [change](https://github.com/dask/distributed/pull/5248) this is no longer possible.
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.
```python
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)
```
Is there a way to have a flag to support the previous behaviour?
Thank you
Contributor guide
Assessment
This issue has not been assessed yet.