diff --git a/arctic/_compression.py b/arctic/_compression.py index 8e2d7b1a6..54ee14fe0 100644 --- a/arctic/_compression.py +++ b/arctic/_compression.py @@ -28,7 +28,7 @@ # Enable this when you run the benchmark_lz4.py BENCHMARK_MODE = False -_compress_thread_pool = ThreadPool(LZ4_WORKERS) +_compress_thread_pool = None def enable_parallel_lz4(mode): @@ -86,6 +86,7 @@ def compress_array(str_list, withHC=LZ4_HIGH_COMPRESSION): `list[str` The list of the compressed strings. """ + global _compress_thread_pool if not str_list: return str_list @@ -95,6 +96,8 @@ def compress_array(str_list, withHC=LZ4_HIGH_COMPRESSION): len(str_list) > LZ4_N_PARALLEL and len(str_list[0]) > LZ4_MINSZ_PARALLEL if BENCHMARK_MODE or use_parallel: + if _compress_thread_pool is None: + _compress_thread_pool = ThreadPool(LZ4_WORKERS) return _compress_thread_pool.map(do_compress, str_list) return [do_compress(s) for s in str_list]