summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-12-30 17:49:02 +0100
committerGitHub <noreply@github.com>2021-12-30 17:49:02 +0100
commit30d1385599beefc8f65f3c71cbbb52666bf1420b (patch)
tree9945bd6d71b0b42c0c2c2eda21a969e12e36c77c
parent019794b808271d45f86a7014e9c91cb04458a47a (diff)
downloadpylint-git-30d1385599beefc8f65f3c71cbbb52666bf1420b.tar.gz
Use ``with`` statement in ``parallel.py`` (#5612)
-rw-r--r--pylint/lint/parallel.py10
-rw-r--r--tests/test_check_parallel.py6
2 files changed, 6 insertions, 10 deletions
diff --git a/pylint/lint/parallel.py b/pylint/lint/parallel.py
index 6dbeed983..b382c42ad 100644
--- a/pylint/lint/parallel.py
+++ b/pylint/lint/parallel.py
@@ -133,11 +133,10 @@ def check_parallel(
# is identical to the linter object here. This is required so that
# a custom PyLinter object can be used.
initializer = functools.partial(_worker_initialize, arguments=arguments)
- pool = multiprocessing.Pool( # pylint: disable=consider-using-with
+ with multiprocessing.Pool(
jobs, initializer=initializer, initargs=[dill.dumps(linter)]
- )
- linter.open()
- try:
+ ) as pool:
+ linter.open()
all_stats = []
all_mapreduce_data = collections.defaultdict(list)
@@ -164,9 +163,6 @@ def check_parallel(
all_stats.append(stats)
all_mapreduce_data[worker_idx].append(mapreduce_data)
linter.msg_status |= msg_status
- finally:
- pool.close()
- pool.join()
_merge_mapreduce_data(linter, all_mapreduce_data)
linter.stats = merge_stats([linter.stats] + all_stats)
diff --git a/tests/test_check_parallel.py b/tests/test_check_parallel.py
index 4fa49d148..bc27530f3 100644
--- a/tests/test_check_parallel.py
+++ b/tests/test_check_parallel.py
@@ -189,10 +189,10 @@ class TestCheckParallelFramework:
"""
linter = PyLinter(reporter=Reporter())
linter.attribute = argparse.ArgumentParser() # type: ignore[attr-defined]
- pool = multiprocessing.Pool( # pylint: disable=consider-using-with
+ with multiprocessing.Pool(
2, initializer=worker_initialize, initargs=[dill.dumps(linter)]
- )
- pool.imap_unordered(print, [1, 2])
+ ) as pool:
+ pool.imap_unordered(print, [1, 2])
def test_worker_check_single_file_uninitialised(self) -> None:
pylint.lint.parallel._worker_linter = None