-
-
Notifications
You must be signed in to change notification settings - Fork 748
Fix WhoHas/HasWhat async usage #4860
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
Conversation
|
There are a number of places inside of scheduler.py where we rely on dictionary methods which didn't play nicely. For example:
In b9c42fc, I thought it best just to handle the return explicitly for async clients. So we could keep the fancy repr for ipython while we sort through a nice model for leveraging HTML in the repr |
jrbourbeau
left a comment
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.
Thanks for the quick fix @quasiben
distributed/tests/test_client.py
Outdated
| await s.close() | ||
|
|
||
|
|
||
| @gen_cluster(client=False, timeout=None) |
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.
Curious why timeout=None is needed here
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.
Not needed -- I'll take it out
distributed/tests/test_client.py
Outdated
|
|
||
| @gen_cluster(client=False, timeout=None) | ||
| async def test_async_whowhat(s, a, b): | ||
| c = await Client(s.address, asynchronous=True) |
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.
Can we set client=True in gen_cluster? That should return an asynchronous Client. It will also automatically be closed at the end, so we can avoid an explicit .close() call
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.
👍
distributed/client.py
Outdated
| if self.asynchronous: | ||
| return self.sync(self.scheduler.has_what, workers=workers, **kwargs) | ||
| else: | ||
| return HasWhat( | ||
| self.sync(self.scheduler.has_what, workers=workers, **kwargs) | ||
| ) |
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.
Similar comment here
FWIW I think that's because distributed/distributed/scheduler.py Line 482 in 2e01873
|
Co-authored-by: James Bourbeau <jrbourbeau@users.noreply.github.com>
|
Should it be a Or is it both? If the latter, maybe it should be It's worth noting when variables are too flexible it really makes it hard to Cythonize things efficiently |
|
Things like distributed/distributed/scheduler.py Line 1292 in 2e01873
However, client-side methods like distributed/distributed/scheduler.py Lines 6174 to 6189 in 2e01873
where the thing that is actually returned to the (client-side) user is a |
Admittedly, I didn't know the |
|
Appears to be working. @jrbourbeau do you have any more thoughts on this? 🙂 |
|
Hmm, unfortunately it looks like the diff --git a/distributed/tests/test_client.py b/distributed/tests/test_client.py
index 93aae7aa..c4b0c96f 100644
--- a/distributed/tests/test_client.py
+++ b/distributed/tests/test_client.py
@@ -58,6 +58,7 @@ from distributed.comm import CommClosedError
from distributed.compatibility import MACOS, WINDOWS
from distributed.core import Status
from distributed.metrics import time
+from distributed.objects import HasWhat, WhoHas
from distributed.scheduler import (
COMPILED,
CollectTaskMetaDataPlugin,
@@ -3620,6 +3621,9 @@ async def test_async_whowhat(c, s, a, b):
who_has = await c.who_has()
has_what = await c.has_what()
+ assert type(who_has) is WhoHas
+ assert type(has_what) is HasWhat
+
assert who_has == {x.key: (a.address,)}
assert has_what == {a.address: (x.key,), b.address: ()}results in @gen_cluster(client=True)
async def test_async_whowhat(c, s, a, b):
[x] = await c.scatter([1], workers=a.address)
who_has = await c.who_has()
has_what = await c.has_what()
> assert type(who_has) is WhoHas
E AssertionError: assert <class 'dict'> is WhoHas
E + where <class 'dict'> = type({'int-c0a8a20f903a4915b94db8de3ea63195': ('tcp://127.0.0.1:59649',)})
distributed/tests/test_client.py:3624: AssertionErrorI'm not sure why the |
…when using sync client
|
reverted but also added a test based on your last comment |
jrbourbeau
left a comment
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.
Thanks @quasiben, the changes here look good to me. Let's merge after CI finishes.
I'm not sure why the HasWhat / WhoHas subclasses aren't making it to the client process right now
FWIW I think this has to do with msgpack's handling of dict subclasses
In [1]: from distributed.objects import HasWhat
In [2]: x = HasWhat()
In [3]: type(x)
Out[3]: distributed.objects.HasWhat
In [4]: from distributed.protocol.serialize import msgpack_dumps, msgpack_loads
In [5]: x_roundtrip = msgpack_loads(*msgpack_dumps(x))
In [6]: type(x_roundtrip)
Out[6]: dict@jakirkham @madsbk may find the above snippet interesting
|
Yeah was wondering if we needed to do something special with serialization (like defining how to serialize this object). Though still would have expected the That said, this seems like we are getting into the weeds right before a release. So probably best to punt and revisit after |
|
CI finished green. Thanks @jrbourbeau and @jakirkham |
* move object WhoHas/HasWhat to scheduler * remove whohas from scheduler -- bail on fancy repr for async * lint * Update distributed/client.py Co-authored-by: James Bourbeau <jrbourbeau@users.noreply.github.com> * code clean up and cleaner tests * use Whohas/HasWht in get_whohas methods * revert objects usage in scheduler and add assertive test for objects when using sync client Co-authored-by: James Bourbeau <jrbourbeau@users.noreply.github.com>
black distributed/flake8 distributed/isort distributedFixes an issue first identified by @crusaderky #4853 (comment)
cc @jrbourbeau