TypeError: cannot pickle 'property' object
See original GitHub issueI 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:
- Created 4 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you @pierreglaser
I ran into this issue in the ray package, which also packages its own copy of
cloudpickle
. The problem of the unpicklableproperty
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
Hi, thanks for the report.
FYI,
joblib
vendors its owncloudpickle
(insidejoblib.externals.cloudpickle
), which gets updated once in a while. Socloudpickle
andjoblib.externals.cloudpickle
may or may not behave the same way depending on which version ofjoblib
andcloudpickle
is installed on your environment.That being said, the last
joblib
release vendorscloudpickle==1.2.2
which had a bug affecting the pickling ofproperty
objects onPython 3.8
(see cloudpipe/cloudpickle#329)The future joblib release will contain
cloudpickle == 1.4.1
, and thus should not have this issue.