Skip to content

Commit 424e8ee

Browse files
Merge pull request #330 from codecov/joseph/thread-pool-method
Change thread pool method in process_files
2 parents da34344 + e523a84 commit 424e8ee

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

codecov_cli/services/staticanalysis/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import typing
55
from functools import partial
6-
from multiprocessing import get_context
6+
from multiprocessing import Pool
77
from pathlib import Path
88

99
import click
@@ -187,7 +187,9 @@ async def process_files(
187187
length=len(files_to_analyze),
188188
label="Analyzing files",
189189
) as bar:
190-
with get_context("fork").Pool(processes=numberprocesses) as pool:
190+
# https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods
191+
# from the link above, we want to use the default start methods
192+
with Pool(processes=numberprocesses) as pool:
191193
file_results = pool.imap_unordered(mapped_func, files_to_analyze)
192194
for result in file_results:
193195
bar.update(1, result)

tests/services/static_analysis/test_static_analysis_service.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ async def test_process_files_with_error(self, mocker):
3232
],
3333
)
3434
)
35-
mock_get_context = mocker.patch(
36-
"codecov_cli.services.staticanalysis.get_context"
37-
)
35+
mock_pool = mocker.patch("codecov_cli.services.staticanalysis.Pool")
3836

3937
def side_effect(config, filename: FileAnalysisRequest):
4038
if filename.result_filename == "correct_file.py":
@@ -59,12 +57,12 @@ def imap_side_effect(mapped_func, files):
5957
results.append(mapped_func(file))
6058
return results
6159

62-
mock_get_context.return_value.Pool.return_value.__enter__.return_value.imap_unordered.side_effect = (
60+
mock_pool.return_value.__enter__.return_value.imap_unordered.side_effect = (
6361
imap_side_effect
6462
)
6563

6664
results = await process_files(files_found, 1, {})
67-
mock_get_context.return_value.Pool.return_value.__enter__.return_value.imap_unordered.assert_called()
65+
mock_pool.return_value.__enter__.return_value.imap_unordered.assert_called()
6866
assert mock_analyze_function.call_count == 2
6967
assert results == dict(
7068
all_data={"correct_file.py": {"hash": "abc123"}},

0 commit comments

Comments
 (0)