class PickleableLock(object): def __init__(self): self.lock = Lock() def __getstate__(self): return '' def __setstate__(self, value): return self.__init__() def __getattr__(self, item): return self.lock.__getattr__(item) def __enter__(self): self.lock.__enter__() def __exit__(self, exc_type, exc_val, exc_tb): self.lock.__exit__(exc_type, exc_val, exc_tb)