Skip to content

Commit

Permalink
fix pickle
Browse files Browse the repository at this point in the history
  • Loading branch information
rdemaria committed Aug 16, 2024
1 parent ebb22a4 commit 341319a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions xobjects/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ def new_buffer(self, capacity=1048576):
self._allocations += 1
return buf

def __getstate__(self):
state = self.__dict__
del state["_buffers"]
return state

def __setstate__(self, state):
self.__dict__.update(state)
self._buffers = weakref.WeakSet()

@property
def buffers(self):
return list(self._buffers)
Expand Down
3 changes: 3 additions & 0 deletions xobjects/context_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import uuid
from pathlib import Path
from typing import Callable, Dict, List, Sequence, Tuple
import weakref

from .general import _print

Expand Down Expand Up @@ -645,10 +646,12 @@ def openmp_enabled(self):
def __getstate__(self):
state = self.__dict__.copy()
state["_kernels"] = {}
del state["_buffers"]
return state

def __setstate__(self, state):
self.__dict__.update(state)
self._buffers = weakref.WeakSet()


class BufferByteArray(XBuffer):
Expand Down

0 comments on commit 341319a

Please sign in to comment.