Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PicklingError when trying to pickle a VSC randobj #179

Open
smccans opened this issue May 23, 2023 · 2 comments
Open

PicklingError when trying to pickle a VSC randobj #179

smccans opened this issue May 23, 2023 · 2 comments

Comments

@smccans
Copy link

smccans commented May 23, 2023

Is it possible to pickle a class that has the @vsc.randobj decorator? I get a PicklingError when trying to do something like this code below. Using the dill module instead of pickle results in the same error.

import vsc
import pickle

@vsc.randobj
class Sample():
    pass

obj = Sample()
string = pickle.dumps(obj)

Running that results in this error:

Traceback (most recent call last):
  File "test_vsc.py", line 10, in <module>
    string = pickle.dumps(obj)
_pickle.PicklingError: Can't pickle <class 'vsc.rand_obj.Sample'>: attribute lookup Sample on vsc.rand_obj failed
@mballance
Copy link
Member

Good question, @smccans. Can you share a bit more about your intended usecase? My understanding is that Pickling is used to capture some 'persistent' view of an object that can be stored and/or transported, then 'restored' to its original state. I'll have to give thought to what state, exactly, would need to be stored in order to reconstruct the object.
I will try to read up a bit on Pickling. I suspect there are some hooks that can be used to properly handle corner cases like 'vsc.rand_obj'.

-Matthew

@smccans
Copy link
Author

smccans commented May 30, 2023

I'm trying to create a vsc.rand_obj and do some randomization on one system and then send that object over the network to one or more other systems. I could just send the seed and do the randomization again on the other systems, but I thought I might get a little better performance by just doing the randomization once.
As a workaround for now, I'm using jsonpickle to encode the vsc.rand_obj as a json string. Then I replace vsc.rand_obj in that json string with the correct module path (__main__ in my original example). This seems to be working so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants