google / google/gin-config

Error when pickling objects configured with Gin

Open
#196 2 comments 3 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.2k
Forks
122
Avg merge
5d 10h
Merged PRs (30d)
2

Description

*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: https://github.com/google/gin-config/issues/8

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.