cloudpipe / cloudpipe/cloudpickle

Unable to reference global variables in serialized functions

Open
#452 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.9k
Forks
195
Avg merge
1d 10h
Merged PRs (30d)
1

Description

When pickling a function that references a global variable, the global variable is no longer referenced.

```

import cloudpickle

global x
x = 123

def increment_x():
global x
x += 1
return x

copy_of_increment_x = cloudpickle.loads(cloudpickle.dumps(increment_x))

print('Expecting 124 - got ' + str(increment_x()))
print('Expecting 125 - got ' + str(copy_of_increment_x()))

```

The following will print
Expecting 124 - got 124
Expecting 125 - got 124

Is there a way to reference globals?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.