Skip to content

Commit

Permalink
FrameCacheImageSeries: remove non-pickleable attributes from state
Browse files Browse the repository at this point in the history
The multiprocessing library uses pickle to serialize objects between processes. This
was creating an issue for FrameCacheImageSeries since it contained a non-pickable attribute.
We now skip this from the state. This should not affect the functionality of the framecache since
it was used to make sure that only one thread was populating the cache at a time. The same is true
now. In every process only one thread at a time can populate the cache
  • Loading branch information
ChristosT committed Nov 25, 2024
1 parent ba52e1a commit 2c1cbca
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions hexrd/imageseries/load/framecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,23 @@ def __iter__(self):
# @memoize
def __len__(self):
return self._nframes

def __getstate__(self):
# Remove any non-pickleable attributes
to_remove = [
'_load_framelist_lock',
]

# Make a copy of the dict to modify
state = self.__dict__.copy()

# Remove them
for attr in to_remove:
state.pop(attr)

return state

def __setstate__(self, state):
self.__dict__.update(state)
# initialize lock after un-pickling
self._load_framelist_lock = Lock()

0 comments on commit 2c1cbca

Please sign in to comment.