#37063 closed New feature (duplicate)

PicklingError: Can't pickle Task

Reported by: Johannes Maron Owned by:
Component: Tasks Version: 6.0
Severity: Normal Keywords:
Cc: Johannes Maron Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi there,

I am working on Django tasks executor and noticed that the current implementation has a few oddities and bugs that we might want to address in future releases.

For now, let's focus on the biggest one, Tasks, and therefore TasksResults can't be pickled.
However, it is essential to use multiprocessing and to utilize the entire CPU to execute tasks.

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "$HOME/.local/share/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/multiprocessing/reduction.py", line 51, in dumps
    cls(buf, protocol).dump(obj)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
_pickle.PicklingError: Can't pickle <function cpu_heavy_task at 0x10986eae0>: it's not the same object as tests.testapp.tasks.cpu_heavy_task

Of course, you can serialize and deserialize objects yourself, but that's a pretty high bar to clear.
Especially since it's a fairly easy fix for Django.

Cheers!
Joe

Change History (2)

comment:1 by Johannes Maron, 71 minutes ago

Note: IMHO this also cannot be solved with subclassing Task or TaskResult.

comment:2 by Jacob Walls, 3 minutes ago

Easy pickings: unset
Resolution: duplicate
Status: newclosed
Type: UncategorizedNew feature

Hey Joe, this one is almost ready to merge, just would like a confirming review from someone. Fancy a look? PR

Duplicate of #36919

Note: See TracTickets for help on using tickets.
Back to Top