Repository navigation
Closed
dask/distributed
#9169Labels
bugSomething is brokenneeds attentionIt's been a while since this was pushed on. Needs attention from the owner or a maintainer.p2Affects more than a few users but doesn't prevent core functions
Description
Describe the issue:
As of Python 3.12, pickling an itertools object has been deprecated, and in Python 3.14, it will no longer work. This causes a failure in test_multiple_repartition_partition_size:
___________________ test_multiple_repartition_partition_size ___________________
[gw2] linux -- Python 3.14.0 /usr/bin/python3
def test_multiple_repartition_partition_size():
b = db.from_sequence(range(1, 100), npartitions=1)
total_mem = sum(b.map_partitions(total_mem_usage).compute())
c = b.repartition(partition_size=(total_mem // 2))
assert c.npartitions >= 2
assert_eq(b, c)
> d = c.repartition(partition_size=(total_mem // 5))
dask/bag/tests/test_bag.py:1305:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
dask/bag/core.py:1694: in repartition
return repartition_size(self, partition_size)
dask/bag/core.py:2666: in repartition_size
mem_usages = bag.map_partitions(total_mem_usage).compute()
../BUILDROOT/usr/lib/python3.14/site-packages/dask/base.py:373: in compute
(result,) = compute(self, traverse=False, **kwargs)
../BUILDROOT/usr/lib/python3.14/site-packages/dask/base.py:681: in compute
results = schedule(expr, keys, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
exc = TypeError(TypeError("cannot pickle 'itertools.chain' object"), ' File "/builddir/build/BUILD/python-dask-2025.7.0-bui... ~~~~~~~~^^^^^^^^^^^\n File "/usr/lib64/python3.14/copy.py", line 146, in deepcopy\n rv = reductor(4)\n')
tb = ' File "/builddir/build/BUILD/python-dask-2025.7.0-build/BUILDROOT/usr/lib/python3.14/site-packages/dask/local.py", l... ~~~~~~~~^^^^^^^^^^^\n File "/usr/lib64/python3.14/copy.py", line 146, in deepcopy\n rv = reductor(4)\n'
def reraise(exc, tb=None):
exc = remote_exception(exc, tb)
> raise exc
E dask.multiprocessing.TypeError: cannot pickle 'itertools.chain' object
E
E Traceback
E ---------
E File "/builddir/build/BUILD/python-dask-2025.7.0-build/BUILDROOT/usr/lib/python3.14/site-packages/dask/local.py", line 258, in execute_task
E result = task(data)
E File "/builddir/build/BUILD/python-dask-2025.7.0-build/BUILDROOT/usr/lib/python3.14/site-packages/dask/_task_spec.py", line 759, in __call__
E return self.func(*new_argspec)
E ~~~~~~~~~^^^^^^^^^^^^^^
E File "/builddir/build/BUILD/python-dask-2025.7.0-build/BUILDROOT/usr/lib/python3.14/site-packages/dask/_task_spec.py", line 199, in _execute_subgraph
E res = execute_graph(final, keys=[outkey])
E File "/builddir/build/BUILD/python-dask-2025.7.0-build/BUILDROOT/usr/lib/python3.14/site-packages/dask/_task_spec.py", line 1078, in execute_graph
E cache[key] = node(cache)
E ~~~~^^^^^^^
E File "/builddir/build/BUILD/python-dask-2025.7.0-build/BUILDROOT/usr/lib/python3.14/site-packages/dask/_task_spec.py", line 759, in __call__
E return self.func(*new_argspec)
E ~~~~~~~~~^^^^^^^^^^^^^^
E File "/builddir/build/BUILD/python-dask-2025.7.0-build/BUILDROOT/usr/lib/python3.14/site-packages/dask/bag/core.py", line 2655, in total_mem_usage
E partition = reify(deepcopy(partition))
E ~~~~~~~~^^^^^^^^^^^
E File "/usr/lib64/python3.14/copy.py", line 146, in deepcopy
E rv = reductor(4)
../BUILDROOT/usr/lib/python3.14/site-packages/dask/multiprocessing.py:112: TypeErrorMinimal Complete Verifiable Example:
pytest
Environment:
- Dask version: 2025.7.0
- Python version: 3.14
- Operating System: Fedora Rawhide
- Install method (conda, pip, source): source
Metadata
Metadata
Assignees
Labels
bugSomething is brokenneeds attentionIt's been a while since this was pushed on. Needs attention from the owner or a maintainer.p2Affects more than a few users but doesn't prevent core functions
Activity
QuLogic commentedon Aug 5, 2025
Forgot to add a link to the Python change: https://docs.python.org/3.14/whatsnew/3.14.html#itertools
[-]itertools is no longer picklable[/-][+]itertools is no longer copyable/picklable[/+]jrbourbeau commentedon Aug 5, 2025
Thanks for flagging @QuLogic. I've been able to reproduce with
But haven't yet been able to track down where the
itertools.chainobject is coming from. I think a reasonable thing to do here would be to replace problematicitertoolsroutines with custom utility functions.mrocklin commentedon Aug 5, 2025
toolz.concatis probably a serializable drop-in replacement FWIW.jrbourbeau commentedon Aug 5, 2025
Ah, nice. Even better. It looks like
toolz.concatusesitertoolsinternallyso we'll want to make sure that whatever we shift to avoids the need to serialize
itertoolsobjects. But yeah, if we can pull in existing utilities elsewhere (like fromtoolz) instead of rolling our own, that'd be great.mrocklin commentedon Aug 5, 2025
Ah, maybe maybe toolz isn't appropriate then. Sorry if my comment led us astray.
QuLogic commentedon Aug 14, 2025
I could not find anything either; I think it must be coming from
toolz, actually. Since it occurs for something repartitioned, my guess might be this one?dask/dask/bag/core.py
Lines 2722 to 2747 in d0a9d15