Skip to content

PicklingError with custom classes after cloudpickle #239

@PeterMinin

Description

@PeterMinin

I am getting an error trying to serialize objects of a certain custom class that where previously serialized and de-serialized by cloudpickle (in practice, they are created by dask workers). Here is an example, with some comments below.

import cloudpickle


class A(object):
    pass


class B(A):
    def foo(self):
        super()


NewB = cloudpickle.loads(cloudpickle.dumps(B))
b = NewB()

import dill
dill.dumps(b)

This produces an error:
_pickle.PicklingError: Can't pickle <class '__main__.B'>: it's not the same object as __main__.B
Full stack trace: gist.

The error does not happen in either of the following cases:

  • the classes are imported from a module;
  • class B doesn't use super(), i.e. if it's defined like this:
class B(A):
    def foo(self):
        A()
        B()

Versions:
python - 3.5.2
cloudpickle - 0.4.0
dill - 0.2.7.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions