Skip to content

Commit

Permalink
Merge pull request #281 from neutrinoceros/tst/no_multiprocessing_in_ci
Browse files Browse the repository at this point in the history
BUG: avoid multiprocessing overhead when looping on a single worker
  • Loading branch information
neutrinoceros authored Mar 24, 2024
2 parents 77f92b7 + 0c1e4fa commit b51bf93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions nonos/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import importlib_resources


# process function for parallisation purpose with progress bar
# process function for parallelisation purpose with progress bar
# counterParallel = Value('i', 0) # initialization of a counter
def process_field(
on,
Expand Down Expand Up @@ -540,14 +540,18 @@ def mytrack(iterable, *args, **kwargs): # noqa: ARG001

logger.info("Starting main loop")
tstart = time.time()
with Pool(ncpu) as pool:
list(
mytrack(
pool.imap(func, args["on"]),
description="Processing snapshots",
total=len(args["on"]),
if ncpu == 1:
for on in args["on"]:
func(on)
else:
with Pool(ncpu) as pool:
list(
mytrack(
pool.imap(func, args["on"]),
description="Processing snapshots",
total=len(args["on"]),
)
)
)
if not show:
logger.info("Operation took {:.2f}s", time.time() - tstart)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def test_pbar(simulation_dir, capsys, tmp_path):

out, err = capsys.readouterr()
assert err == ""
assert "Processing snapshots" in out
assert out == ""
assert ret == 0


Expand Down

0 comments on commit b51bf93

Please sign in to comment.