Cloudpickle 1.5.0, dill 0.3.2 or 0.3.1.1:
import dill
import cloudpickle
class Foo:
def bar(self, param: int):
hello = "Hello"
def baz() -> None:
print(hello, param)
cloudpickle.loads(cloudpickle.dumps(baz))()
if __name__ == '__main__':
Foo().bar(param=2)
This fails with ValueError: Cell is empty.
Without the dill import, or with the dill import after the cloudpickle import, and it's all fine.
If the inner function is just
def baz() -> None:
print("Hello world")
then it's also fine.
The problem seems to be if the inner function captures anything in its closure.
According to the cloudpickle dev cloudpipe/cloudpickle#393
In this precise case, importing dill triggers a global side effect which add a high-priority cell reducer that is not compatible with cloudpickle's way of reducing cells.
is there a way to get around this, and have both dill and cloudpickle work?
Cloudpickle 1.5.0, dill 0.3.2 or 0.3.1.1:
This fails with
ValueError: Cell is empty.Without the
dillimport, or with the dill import after the cloudpickle import, and it's all fine.If the inner function is just
then it's also fine.
The problem seems to be if the inner function captures anything in its closure.
According to the cloudpickle dev cloudpipe/cloudpickle#393
is there a way to get around this, and have both dill and cloudpickle work?