Skip to content

register_pickle_by_value appears to not deliver monkeypatches to receiver #586

@sgillies

Description

@sgillies

Should I expect register_pickle_by_value() to deliver monkeypatches? I don't know if what I'm observing is a bug or only missing functionality.

I have two python environments, A and B. Each has cloudpickle 3.1.2 installed and also a package that I'm developing at work. Let's call it "tdb". I run a script in environment A that looks like this:

import sys

import cloudpickle
import tdb

# monkeypatch an attribute of tdb.
tdb.my_function = lambda *args, **kwargs: ["fake", "values"]

def func():
    return tdb.my_function()

assert func() == ["fake", "values"]

cloudpickle.register_pickle_by_value(tdb)
pickle_data = cloudpickle.dumps(func, protocol=4)
sys.stdout.buffer.write(pickle_data)

I'm piping the output to a script that runs in environment B

import pickle
import sys

pickle_data = sys.stdin.buffer.read()
print(pickle_data)

func = pickle.loads(pickle_data)
print(func())

But I see the original tdb.my_function being called in environment B, not my monkeypatch.

The odd thing is that I can see lambda when I print the pickle stream in environment B. It's there in some sense, but isn't being understood on the receiver side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions