Skip to content

Update _cluster_info dict in init - #5305

Merged
jrbourbeau merged 2 commits into
dask:mainfrom
jacobtomlinson:cluster-info-update
Sep 29, 2021
Merged

jrbourbeau merged 2 commits into
dask:mainfrom
jacobtomlinson:cluster-info-update

Conversation

@jacobtomlinson

@jacobtomlinson jacobtomlinson commented Sep 10, 2021 •

Copy link
Copy Markdown
Member

The _cluster_info dict is designed to be populated during __init__. But some FooCluster subclass implementations call super().__init__() first, and some last.

For instance all SpecCluster implementations require the super init to be called last because in sync mode the super starts the event loop and enters the _start method during init.

This change avoids the _cluster_info from being overwritten in either scenario.

@jrbourbeau jrbourbeau left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jacobtomlinson! I'm probably just missing something, but it's not clear to me why the current code in main is problematic, regardless of what order Cluster.__init__(...) is called in a subclass' __init__ method. Maybe a subclass' __init__ method mutates or inspects self._cluster_info? Is there a test we could add which illustrates the problematic behavior?

EDIT: To be clear, the changes here seem reasonable, I think I'm just missing a piece related to why they're needed

@jacobtomlinson

Copy link
Copy Markdown
Member Author

Maybe a subclass' init method mutates or inspects self._cluster_info?

Yes this is the reason. The _cluster_info dict is designed to be mutated by a subclass during __init__.

@jrbourbeau jrbourbeau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I forgot to merge this in. Thanks @jacobtomlinson!

@jrbourbeau
jrbourbeau merged commit b8d44cb into dask:main Sep 29, 2021
@jacobtomlinson
jacobtomlinson deleted the cluster-info-update branch September 30, 2021 10:05
async def test_cluster_info():
class FooCluster(Cluster):
def __init__(self):
self._cluster_info["foo"] = "bar"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this mutation now applies to all other subclasses of Cluster - and isn't threadsafe:

>>> from distributed.deploy import Cluster
>>> class FooCluster(Cluster):
...     def __init__(self):
...         self._cluster_info["foo"] = "bar"
...         super().__init__(asynchronous=False)
... 
>>> c = FooCluster()
>>> c._cluster_info
{'name': 'c74e5491', 'type': '__main__.FooCluster', 'foo': 'bar'}
>>> FooCluster._cluster_info
{'foo': 'bar'}
>>> Cluster._cluster_info
{'foo': 'bar'}
>>> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants