Browse Source

Merge pull request #2952 from enkore/f/killthreads

delete various nogil and threading related lines
enkore 7 years ago
parent
commit
818e5c8e01
3 changed files with 8 additions and 14 deletions
  1. 2 4
      src/borg/compress.pyx
  2. 2 4
      src/borg/crypto/low_level.pyx
  3. 4 6
      src/borg/helpers.py

+ 2 - 4
src/borg/compress.pyx

@@ -126,8 +126,7 @@ class LZ4(CompressorBase):
         osize = LZ4_compressBound(isize)
         buf = buffer.get(osize)
         dest = <char *> buf
-        with nogil:
-            osize = LZ4_compress_limitedOutput(source, dest, isize, osize)
+        osize = LZ4_compress_limitedOutput(source, dest, isize, osize)
         if not osize:
             raise Exception('lz4 compress failed')
         return super().compress(dest[:osize])
@@ -150,8 +149,7 @@ class LZ4(CompressorBase):
             except MemoryError:
                 raise DecompressionError('MemoryError')
             dest = <char *> buf
-            with nogil:
-                rsize = LZ4_decompress_safe(source, dest, isize, osize)
+            rsize = LZ4_decompress_safe(source, dest, isize, osize)
             if rsize >= 0:
                 break
             if osize > 2 ** 27:  # 128MiB (should be enough, considering max. repo obj size and very good compression)

+ 2 - 4
src/borg/crypto/low_level.pyx

@@ -207,8 +207,7 @@ def hmac_sha256(key, data):
     cdef int key_len = len(key)
     cdef unsigned char md[32]
     try:
-        with nogil:
-            rc = HMAC(EVP_sha256(), key_ptr, key_len, <const unsigned char*> data_buf.buf, data_buf.len, md, NULL)
+        rc = HMAC(EVP_sha256(), key_ptr, key_len, <const unsigned char*> data_buf.buf, data_buf.len, md, NULL)
         if rc != md:
             raise Exception('HMAC(EVP_sha256) failed')
     finally:
@@ -219,8 +218,7 @@ def hmac_sha256(key, data):
 cdef blake2b_update_from_buffer(blake2b_state *state, obj):
     cdef Py_buffer buf = ro_buffer(obj)
     try:
-        with nogil:
-            rc = blake2b_update(state, buf.buf, buf.len)
+        rc = blake2b_update(state, buf.buf, buf.len)
         if rc == -1:
             raise Exception('blake2b_update() failed')
     finally:

+ 4 - 6
src/borg/helpers.py

@@ -19,7 +19,6 @@ import stat
 import subprocess
 import sys
 import textwrap
-import threading
 import time
 import uuid
 from binascii import hexlify
@@ -809,7 +808,7 @@ def format_archive(archive):
 
 class Buffer:
     """
-    provide a thread-local buffer
+    managed buffer (like a resizable bytearray)
     """
 
     class MemoryLimitExceeded(Error, OSError):
@@ -822,13 +821,12 @@ class Buffer:
         """
         assert callable(allocator), 'must give alloc(size) function as first param'
         assert limit is None or size <= limit, 'initial size must be <= limit'
-        self._thread_local = threading.local()
         self.allocator = allocator
         self.limit = limit
         self.resize(size, init=True)
 
     def __len__(self):
-        return len(self._thread_local.buffer)
+        return len(self.buffer)
 
     def resize(self, size, init=False):
         """
@@ -840,7 +838,7 @@ class Buffer:
         if self.limit is not None and size > self.limit:
             raise Buffer.MemoryLimitExceeded(size, self.limit)
         if init or len(self) < size:
-            self._thread_local.buffer = self.allocator(size)
+            self.buffer = self.allocator(size)
 
     def get(self, size=None, init=False):
         """
@@ -849,7 +847,7 @@ class Buffer:
         """
         if size is not None:
             self.resize(size, init)
-        return self._thread_local.buffer
+        return self.buffer
 
 
 @lru_cache(maxsize=None)