Skip to content
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

Add worker_class argument to LocalCluster #2625

Merged
merged 4 commits into from
Apr 20, 2019

Conversation

pentschev
Copy link
Member

Allows instantiating workers subclassed from Worker (e.g., CUDAWorker) in LocalCluster.

@mrocklin

@pentschev
Copy link
Member Author

It looks like the failures are not related to this PR, but I'm not quite sure about it.

Copy link
Member

@mrocklin mrocklin left a comment

Choose a reason for hiding this comment

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

In general I like the change. Some suggestions below.

@@ -203,6 +206,8 @@ def __init__(
if security:
self.worker_kwargs["security"] = security

self.worker_class = worker_class
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.worker_class = worker_class
if not worker_class:
if processes:
worker_class = Nanny
else:
worker_class = Worker
self.worker_class = worker_class

kwargs["quiet"] = True
else:
W = Worker
W = self.worker_class or Worker

w = yield W(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
w = yield W(
w = yield self.worker_class(

kwargs["quiet"] = True
else:
W = Worker
W = self.worker_class or Worker
Copy link
Member

Choose a reason for hiding this comment

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

If you accept the other changes, then we can probably drop the conditional above (it's effectively now handled in the constructor)

We might also remove the self.processes attribute, which seems to be effectively replaced and generalized by self.worker_class.

We should have something like the following though to maintain previous behavior.

if self.worker_class is Nanny:
    kwargs['quiet'] = True

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, your changes look fine to me. I will push a commit.

@mrocklin
Copy link
Member

This could also use a test. Maybe something like ...

def test_worker_class(loop):
    class MyWorker(Worker):
        pass

    with LocalCluster(n_workers=2, loop=loop, worker_class=MyWorker, scheduler_port=0, dashboard_address=None) as cluster:
        assert all(isinstance(w, MyWorker) for w in cluster.workers)

@pentschev
Copy link
Member Author

Thanks for the suggestion, I was really unsure how to test this. I extended your test a bit to test both Worker and Nanny.

@mrocklin
Copy link
Member

I should have mentioned that we recently switched to using black for code styling. It looks like you found that out. I need to add docs for this in a more prominent place, but you may want to try installing pre commit hooks

@pentschev
Copy link
Member Author

I should have mentioned that we recently switched to using black for code styling. It looks like you found that out. I need to add docs for this in a more prominent place, but you may want to try installing pre commit hooks

Ah nice, didn't know about this, thanks for that!

I think the errors are not related to this PR.

@mrocklin
Copy link
Member

mrocklin commented Apr 19, 2019 via email

@pentschev
Copy link
Member Author

No worries, let me know if you need help with them.

@mrocklin mrocklin merged commit f459af1 into dask:master Apr 20, 2019
@pentschev pentschev deleted the localcluster-workerclass branch November 11, 2020 17:31
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.

2 participants