Commit 330de433 authored by Laurent Bachelier's avatar Laurent Bachelier 🐧 Committed by Vincent A

config: Allow extra classes to be pickled properly

parent d20e9c08
......@@ -64,6 +64,16 @@ class ForkingConfig(object):
super(ForkingConfig, self).__exit__(t, v, tb)
def __getstate__(self):
d = self.__dict__.copy()
d.pop('lock', None)
return d
def __setstate__(self, d):
for k, v in d.items():
setattr(self, k, v)
def time_buffer(since_seconds=None, last_run=True, logger=False):
def decorator_time_buffer(func):
......@@ -116,3 +126,20 @@ class TimeBufferConfig(object):
def __exit__(self, t, v, tb):
super(TimeBufferConfig, self).__exit__(t, v, tb)
def __getstate__(self):
d = super(TimeBufferConfig, self).__getstate__()
except AttributeError:
d = self.__dict__.copy()
# When decorated, it is not serializable.
# The decorator will be added again by __setstate__.
d.pop('save', None)
return d
def __setstate__(self, d):
# Add the decorator if needed
for k, v in d.items():
setattr(self, k, v)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment