-
-
Notifications
You must be signed in to change notification settings - Fork 719
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
Raise plugin exceptions on Worker.start() #4298
Changes from 2 commits
128c983
3224d42
3eae880
fa81d3d
cc3bec5
f85475f
dde7a09
df4a6cb
51340a5
f93ab5b
5604af5
d323913
7552423
f6a699a
560bb55
dc3aaeb
d44edb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -407,6 +407,24 @@ def __str__(self): | |
assert "Bar" in str(e.__cause__) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_plugin_exception(): | ||
class MyException(Exception): | ||
def __init__(self, msg): | ||
self.msg = msg | ||
|
||
def __str__(self): | ||
return "MyException(%s)" % self.msg | ||
|
||
class MyPlugin: | ||
def setup(self, worker=None): | ||
raise MyException("Foo") | ||
mrocklin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
s = await Scheduler(port=8007) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend using `async with Scheduler(port=0) as s:
jrbourbeau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with pytest.raises(MyException): | ||
await Worker(s.address, plugins={MyPlugin(),}) | ||
|
||
|
||
@gen_cluster() | ||
async def test_gather(s, a, b): | ||
b.data["x"] = 1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1139,9 +1139,12 @@ async def start(self): | |
|
||
setproctitle("dask-worker [%s]" % self.address) | ||
|
||
await asyncio.gather( | ||
plugins_msgs = await asyncio.gather( | ||
*[self.plugin_add(plugin=plugin) for plugin in self._pending_plugins] | ||
) | ||
for msg in plugins_msgs: | ||
if msg["status"] != "OK": | ||
raise msg["exception"].data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this is the right way of raising the exception that's being created by I'm not sure if this is also being handled correctly or if this is a bug in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect that if you just remove the try-except and special handling in the plugin_add function that things may just work. I suspect that the standard machinery around rpc will handle the exception comfortably. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure though, this is just a guess. I give it a 50/50 chance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think your suggestion would work in There's also a chance that I'm overlooking something and your suggestion would work in all situations, is that the case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Functions used as handlers handle exceptions in the same way that this function is doing manually. I recommend trying things, seeing if everything passes, and reporting back. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I did that now. What I wanted to prevent is breaking some untested behavior, just like this isn't being tested currently I believe that may break some other use case out there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, perhaps we could add a small test then? I suspect that this would be the same as your current test, but you would use a pre-existing worker (just use gen_cluster rather than create things manually) and then call the client.register_plugin method (I think that that's the name but am not sure) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Matt, I really wasn't aware how to use that properly. I now added a test for If this is still too dirty, the only idea I have right now to avoid the |
||
self._pending_plugins = () | ||
|
||
await self._register_with_scheduler() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.