question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: cannot pickle 'property' object

See original GitHub issue

I experience a problem with Python class properties and joblib. Somehow it is not possible to pickle them. See this minimal reproducible example:

import multiprocessing

from joblib import Parallel, delayed


class Task:
    def run(self):
        print(self.hello_world)

    @property
    def hello_world(self):
        return "hello world"


if __name__ == "__main__":
    Parallel(n_jobs=multiprocessing.cpu_count())([delayed(lambda: Task().run())()])

This code fails raising TypeError: cannot pickle 'property' object. It works if you replace the property with a method get_hello_world and call self.get_hello_world() in Task.run.

Environment:

  • Python 3.8.1
  • joblib 0.14.1
  • macOS Catalina 10.15.2

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
KristianHolsheimercommented, May 14, 2020

Thank you @pierreglaser

I ran into this issue in the ray package, which also packages its own copy of cloudpickle. The problem of the unpicklable property is resolved (as per your PR from earlier this year… thanks for that)

I’m now having the same issue with abstractproperty. I’ll see if I can put a quick PR ready for cloudpickle. If not, I’ll submit an issue there.

Thanks again, Kris

0reactions
pierreglasercommented, May 13, 2020

Hi, thanks for the report.

FWIW I also checked whether cloudpickle (which I thought was the pickler that loky uses) correctly pickles the object.

FYI, joblib vendors its own cloudpickle (inside joblib.externals.cloudpickle), which gets updated once in a while. So cloudpickle and joblib.externals.cloudpickle may or may not behave the same way depending on which version of joblib and cloudpickle is installed on your environment.

That being said, the last joblib release vendors cloudpickle==1.2.2 which had a bug affecting the pickling of property objects on Python 3.8 (see cloudpipe/cloudpickle#329)

The future joblib release will contain cloudpickle == 1.4.1, and thus should not have this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Establishing why an object can't be pickled - Stack Overflow
I would use dill , which has tools to investigate what inside an object causes your target object to not be picklable. See...
Read more >
TypeError: cannot pickle 'property' object - AIcrowd Forum
When running locally I keep getting this error “TypeError: cannot pickle 'property' object”. It seems to be thrown by cloudpickle when the procgen...
Read more >
How can I solve it ,TypeError: cannot pickle 'dict_keys' object?
1 Answer 1 · Iterate over the dictionary directly · Use in for containment · Convert to the type you want via iterator....
Read more >
Multiprocessing and Pickle, How to Easily fix that?
How to serialize an object using both pickle and dill packages. ... tasks can't be pickled; it would raise an error failing to...
Read more >
Deepcopying property objects results in unexpected TypeError
Python.3.7_3.7.1264.0_x64__qbz5n2kfra8p0\lib\copy.py", line 169, in deepcopy rv = reductor(4) TypeError: can't pickle property objects What ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found