Skip to content

Commit 30d1385

Browse files
authored
Use with statement in parallel.py (#5612)
1 parent 019794b commit 30d1385

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

pylint/lint/parallel.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,10 @@ def check_parallel(
133133
# is identical to the linter object here. This is required so that
134134
# a custom PyLinter object can be used.
135135
initializer = functools.partial(_worker_initialize, arguments=arguments)
136-
pool = multiprocessing.Pool( # pylint: disable=consider-using-with
136+
with multiprocessing.Pool(
137137
jobs, initializer=initializer, initargs=[dill.dumps(linter)]
138-
)
139-
linter.open()
140-
try:
138+
) as pool:
139+
linter.open()
141140
all_stats = []
142141
all_mapreduce_data = collections.defaultdict(list)
143142

@@ -164,9 +163,6 @@ def check_parallel(
164163
all_stats.append(stats)
165164
all_mapreduce_data[worker_idx].append(mapreduce_data)
166165
linter.msg_status |= msg_status
167-
finally:
168-
pool.close()
169-
pool.join()
170166

171167
_merge_mapreduce_data(linter, all_mapreduce_data)
172168
linter.stats = merge_stats([linter.stats] + all_stats)

tests/test_check_parallel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ def test_worker_initialize_pickling(self) -> None:
189189
"""
190190
linter = PyLinter(reporter=Reporter())
191191
linter.attribute = argparse.ArgumentParser() # type: ignore[attr-defined]
192-
pool = multiprocessing.Pool( # pylint: disable=consider-using-with
192+
with multiprocessing.Pool(
193193
2, initializer=worker_initialize, initargs=[dill.dumps(linter)]
194-
)
195-
pool.imap_unordered(print, [1, 2])
194+
) as pool:
195+
pool.imap_unordered(print, [1, 2])
196196

197197
def test_worker_check_single_file_uninitialised(self) -> None:
198198
pylint.lint.parallel._worker_linter = None

0 commit comments

Comments
 (0)