From 4ee45990f9cc63fb320ce8560ccb7be5e2b79b9c Mon Sep 17 00:00:00 2001 From: Nicolas Granger Date: Fri, 12 Apr 2024 21:44:51 +0200 Subject: [PATCH] fix python 3.8 compat --- .github/workflows/tests.yml | 2 +- seqtools/evaluation.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d378c96..0e43d7c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: uses: omnilib/ufmt@action-v1 with: path: seqtools - python-version: "3.11" + python-version: "3.10" unit-tests: runs-on: ubuntu-latest diff --git a/seqtools/evaluation.py b/seqtools/evaluation.py index 7b7075a..b200908 100644 --- a/seqtools/evaluation.py +++ b/seqtools/evaluation.py @@ -109,7 +109,7 @@ def __init__(self, seq, num_workers=0, buffer_size=10, init_fn=None, shm_size=0) ) @staticmethod - def cleanup(job_queue, workers: list[multiprocessing.Process], monitor): + def cleanup(job_queue, workers, monitor): for _ in workers: job_queue.put((-1, -1)) for w in workers: @@ -235,21 +235,24 @@ def buffer_callback(buffer): # serialize it try: if shm_slot_start is None: - payload = pkl.dumps(value, protocol=-1) + payload = pkl.dumps(value, protocol=pkl.HIGHEST_PROTOCOL) else: buffers_limits.clear() shm_offset = shm_slot_start shm_slot_stop = shm_slot_start + shm_slot_size payload = pkl.dumps( - value, protocol=-1, buffer_callback=buffer_callback + value, + protocol=pkl.HIGHEST_PROTOCOL, + buffer_callback=buffer_callback, ) except Exception as e: # gracefully recover failed serialization if success: success = False - msg = "failed to send item {} to parent process, ".format( - idx - ) + "is it picklable? Error message was:\n{}".format(e) + msg = ( + f"failed to send item {idx} to parent process, " + + "is it picklable? Error message was:\n{e}" + ) payload = pkl.dumps(ValueError(msg)) else: # serialize error message because error can't be pickled payload = pkl.dumps(str(value))