Skip to content

Pickling functions using the ROOT module with cloudpickle breaks #6764

@stwunsch

Description

@stwunsch

cloudpickle is the pickling package, which is used in dask and PySpark to serialize and distribute the work, e.g., functions or lambdas. The following reproducer breaks with cloudpickle (but is fine with the standard pickle) and throws the error TypeError: cannot pickle 'ROOTFacade' object, which is highly confusing.

import ROOT
import cloudpickle


def foo():
    ROOT.TH1F()
    return 42

import cloudpickle as pickle # breaks with cloudpickle
#import pickle # works fine with the standard pickle

with open('f.pkl', 'wb') as f:
    pickle.dump(foo, f)

A workaround is moving the import ROOT line inside the function foo, which seems to omit the underlying issue in cloudpickle. We have submitted a bug report to the cloudpickle repository, see cloudpipe/cloudpickle#397.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions