From de9705766a0404c63c89a552d2e321f4fa64b7ca Mon Sep 17 00:00:00 2001 From: Richard Kojedzinszky Date: Tue, 22 Oct 2024 10:38:14 +0200 Subject: [PATCH] feat(py-libzfs): drop lock from context manager https://github.com/truenas/py-libzfs/issues/250 --- .../files/patch-simple-context-manager | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 nas_ports/devel/py-libzfs/files/patch-simple-context-manager diff --git a/nas_ports/devel/py-libzfs/files/patch-simple-context-manager b/nas_ports/devel/py-libzfs/files/patch-simple-context-manager new file mode 100644 index 0000000000000..a0cec886d4341 --- /dev/null +++ b/nas_ports/devel/py-libzfs/files/patch-simple-context-manager @@ -0,0 +1,40 @@ +diff --git libzfs.pyx libzfs.pyx +index 6f9ac94..0b305df 100644 +--- libzfs.pyx ++++ libzfs.pyx +@@ -21,7 +21,6 @@ from libc.stdlib cimport realloc + import errno as py_errno + import urllib.parse + +-GLOBAL_CONTEXT_LOCK = threading.Lock() + logger = logging.getLogger(__name__) + + +@@ -519,24 +518,14 @@ cdef class ZFS(object): + self.proptypes[t] = proptypes + + def __enter__(self): +- GLOBAL_CONTEXT_LOCK.acquire() + return self + + def __exit__(self, exc_type, value, traceback): +- self.__libzfs_fini() +- GLOBAL_CONTEXT_LOCK.release() +- if exc_type is not None: +- raise +- +- def __libzfs_fini(self): +- if self.handle: +- with nogil: +- libzfs.libzfs_fini(self.handle) +- +- self.handle = NULL ++ pass + + def __dealloc__(self): +- ZFS.__libzfs_fini(self) ++ with nogil: ++ libzfs.libzfs_fini(self.handle) + + def asdict(self): + return [p.asdict() for p in self.pools]