|
4 | 4 | import atexit |
5 | 5 | import copy |
6 | 6 | import inspect |
| 7 | +import itertools |
7 | 8 | import json |
8 | 9 | import logging |
9 | 10 | import os |
|
31 | 32 | from tlz import first, groupby, merge, partition_all, valmap |
32 | 33 |
|
33 | 34 | import dask |
34 | | -from dask.base import collections_to_dsk, normalize_token, tokenize |
| 35 | +from dask.base import collections_to_dsk, tokenize |
35 | 36 | from dask.core import flatten, validate_key |
36 | 37 | from dask.highlevelgraph import HighLevelGraph |
37 | 38 | from dask.optimization import SubgraphCallable |
@@ -210,11 +211,15 @@ class Future(WrappedKey): |
210 | 211 |
|
211 | 212 | _cb_executor = None |
212 | 213 | _cb_executor_pid = None |
| 214 | + _counter = itertools.count() |
| 215 | + # Make sure this stays unique even across multiple processes or hosts |
| 216 | + _uid = uuid.uuid4().hex |
213 | 217 |
|
214 | | - def __init__(self, key, client=None, inform=True, state=None): |
| 218 | + def __init__(self, key, client=None, inform=True, state=None, _id=None): |
215 | 219 | self.key = key |
216 | 220 | self._cleared = False |
217 | 221 | self._client = client |
| 222 | + self._id = _id or (Future._uid, next(Future._counter)) |
218 | 223 | self._input_state = state |
219 | 224 | self._inform = inform |
220 | 225 | self._state = None |
@@ -499,8 +504,16 @@ def release(self): |
499 | 504 | except TypeError: # pragma: no cover |
500 | 505 | pass # Shutting down, add_callback may be None |
501 | 506 |
|
| 507 | + @staticmethod |
| 508 | + def make_future(key, id): |
| 509 | + # Can't use kwargs in pickle __reduce__ methods |
| 510 | + return Future(key=key, _id=id) |
| 511 | + |
502 | 512 | def __reduce__(self) -> str | tuple[Any, ...]: |
503 | | - return Future, (self.key,) |
| 513 | + return Future.make_future, (self.key, self._id) |
| 514 | + |
| 515 | + def __dask_tokenize__(self): |
| 516 | + return (type(self).__name__, self.key, self._id) |
504 | 517 |
|
505 | 518 | def __del__(self): |
506 | 519 | try: |
@@ -643,18 +656,6 @@ async def done_callback(future, callback): |
643 | 656 | callback(future) |
644 | 657 |
|
645 | 658 |
|
646 | | -@partial(normalize_token.register, Future) |
647 | | -def normalize_future(f): |
648 | | - """Returns the key and the type as a list |
649 | | -
|
650 | | - Parameters |
651 | | - ---------- |
652 | | - list |
653 | | - The key and the type |
654 | | - """ |
655 | | - return [f.key, type(f)] |
656 | | - |
657 | | - |
658 | 659 | class AllExit(Exception): |
659 | 660 | """Custom exception class to exit All(...) early.""" |
660 | 661 |
|
@@ -3434,9 +3435,11 @@ def compute( |
3434 | 3435 |
|
3435 | 3436 | if traverse: |
3436 | 3437 | collections = tuple( |
3437 | | - dask.delayed(a) |
3438 | | - if isinstance(a, (list, set, tuple, dict, Iterator)) |
3439 | | - else a |
| 3438 | + ( |
| 3439 | + dask.delayed(a) |
| 3440 | + if isinstance(a, (list, set, tuple, dict, Iterator)) |
| 3441 | + else a |
| 3442 | + ) |
3440 | 3443 | for a in collections |
3441 | 3444 | ) |
3442 | 3445 |
|
|
0 commit comments