Skip to content

Commit 3f629b4

Browse files
optimize progress bar handling in autopopulate
1 parent 68ca5d5 commit 3f629b4

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

datajoint/autopopulate.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .errors import DataJointError, LostConnectionError
1010
import signal
1111
import multiprocessing as mp
12+
import contextlib
1213

1314
# noinspection PyExceptionInherit,PyCallingNonCallable
1415

@@ -236,16 +237,12 @@ def handler(signum, frame):
236237
with mp.Pool(
237238
processes, _initialize_populate, (self, jobs, populate_kwargs)
238239
) as pool:
239-
if display_progress:
240-
with tqdm(desc="Processes: ", total=nkeys) as pbar:
240+
with (tqdm(desc="Processes: ", total=nkeys) if display_progress else contextlib.nullcontext()) as pbar:
241241
for error in pool.imap(_call_populate1, keys, chunksize=1):
242242
if error is not None:
243243
error_list.append(error)
244-
pbar.update()
245-
else:
246-
for error in pool.imap(_call_populate1, keys):
247-
if error is not None:
248-
error_list.append(error)
244+
if display_progress:
245+
pbar.update()
249246
self.connection.connect() # reconnect parent process to MySQL server
250247

251248
# restore original signal handler:

0 commit comments

Comments
 (0)