From b895ddd43f5febfc5b8a32342f7e081d04adc9b2 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Thu, 13 Jul 2023 11:37:53 -0400 Subject: [PATCH] Optional lock with no multiprocessing --- scilpy/tracking/tracker.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scilpy/tracking/tracker.py b/scilpy/tracking/tracker.py index c83b9fe76..25226981f 100644 --- a/scilpy/tracking/tracker.py +++ b/scilpy/tracking/tracker.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from contextlib import nullcontext import itertools import logging import multiprocessing @@ -265,7 +266,7 @@ def _reload_data_for_new_process(self, init_args): self.propagator.reset_data(np.load( init_args['data_file_name'], mmap_mode=init_args['mmap_mode'])) - def _get_streamlines(self, chunk_id, lock): + def _get_streamlines(self, chunk_id, lock=None): """ Tracks the n streamlines associates with current process (identified by chunk_id). The number n is the total number of seeds / the number of @@ -277,7 +278,8 @@ def _get_streamlines(self, chunk_id, lock): chunk_id: int This process ID. lock: Lock - The multiprocessing lock + The multiprocessing lock for verbose printing (optional with + single processing). Returns ------- @@ -303,6 +305,8 @@ def _get_streamlines(self, chunk_id, lock): tqdm_text = "#" + "{}".format(chunk_id).zfill(3) if self.verbose: + if lock is None: + lock = nullcontext() with lock: # Note. Option miniters does not work with manual pbar update. # Will verify manually, lower.