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

Error when pickling objects configured with Gin #196

Open
erenz14 opened this issue Sep 13, 2023 · 1 comment
Open

Error when pickling objects configured with Gin #196

erenz14 opened this issue Sep 13, 2023 · 1 comment

Comments

@erenz14
Copy link

erenz14 commented Sep 13, 2023

apologies in advance as I had to type this on my phone

I'm getting the following error when trying to pickle an instance of a class that is configured with gin:

Error:

TypeError: cannot pickle '_thread.lock' object

Code that triggers the error:

import io
import cloudpickle as cp
import gin

@gin.configurable
class Car:
     def __init__(self.horn_noise: str):
          self.horn_noise = horn_noise

     def honk(self):
          print

gin.parse_config_files_and_bindings(config_files=[], bindings=['Car.horn_noise = "beep beep!"'])

car = Car()
car_pkl_bytes = cp.dumps(car)
loaded_car = cp.load(io.BytesIO(car_pkl_bytes)

A workaround is referenced in this issue, but it involves installing dask (or pulling the SerializableLock class into my project) and for some reason even though this workaround allows me to pickle and unpickle a gin configured class, I have to run gin.parse_config_files_and_bindings again after unpickling so that the instance works properly: #8

@erenz14
Copy link
Author

erenz14 commented Sep 13, 2023

Forgot to include my versions:

python=3.8.0
cloudpickle=2.2.1
gin-config=0.5.0

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

1 participant