Skip to content

Recent release brings in all globals #202

@mrocklin

Description

@mrocklin

The following test started to fail in the latest 0.5.6 release:

import numpy as np
import cloudpickle

def test_pickle_globals():
    def f(x):
        return np.sin(x) + np.cos(x)  # requires access to global numpy

    def g():  # some other object not necessary for f
        pass

    d = cloudpickle.loads(cloudpickle.dumps(f)).__globals__
    assert 'g' not in d
    assert set(d) == {'np', '__builtins__'}

It now seems that cloudpickle brings in many more globals into the serialization.

In [6]: set(d)
Out[6]: 
{'In',
 'Out',
 '_',
 '_5',
 '__',
 '___',
 '__builtin__',
 '__builtins__',
 '__doc__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__',
 '_dh',
 '_i',
 '_i1',
 '_i2',
 '_i3',
 '_i4',
 '_i5',
 '_i6',
 '_ih',
 '_ii',
 '_iii',
 '_oh',
 'cloudpickle',
 'd',
 'exit',
 'f',
 'g',
 'get_ipython',
 'np',
 'quit'}

This is causing dask tests to fail

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions