Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for disabling of parallel processing of qmk find and qmk mass-compile. #22160

Merged
merged 14 commits into from
Oct 16, 2023
Merged
Prev Previous commit
Next Next commit
Fixup use of multiprocessing.
  • Loading branch information
tzarc committed Oct 16, 2023
commit 4554eabd0b3e7c2283c80a8d4cceec6d189a3f43
14 changes: 5 additions & 9 deletions lib/python/qmk/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import multiprocessing

from milc import cli
from milc.subcommand import config


@contextlib.contextmanager
Expand All @@ -23,13 +22,6 @@ def parallelize():
else:
parallel_search = cli.config.user.parallel_search

# If we haven't already written a value, write it to the file
if cli.config.user.parallel_search != parallel_search:
cli.args.read_only = False
config.set_config('user', 'parallel_search', parallel_search)
cli.save_config()
cli.config.user.parallel_search = parallel_search

# Non-parallel searches use `map()`
if not parallel_search:
yield map
Expand All @@ -51,4 +43,8 @@ def parallel_map(*args, **kwargs):
"""Effectively runs `map()` but executes it in parallel if necessary.
"""
with parallelize() as map_fn:
return map_fn(*args, **kwargs)
# This needs to be enclosed in a `list()` as some implementations return
# a generator function, which means the scope of the pool is closed off
# before the results are returned. Returning a list ensures results are
# materialised before any worker pool is shut down.
return list(map_fn(*args, **kwargs))