Skip to content

Commit 0f11ff6

Browse files
committed
[fix] Create a shim class providing compat for Pool implementations
On Windows and MacOS the multiprocess library's Pool class is used, whereas on Linux and other platforms the concurrent.futures library's ProcessPoolExecutor is used. These two classes have similar but not identical APIs. This commit introduces a shim class which adapts the API of multiprocess.Pool to be more similar to ProcessPoolExecutor. This commit will close Ericsson#4338.
1 parent a9e7564 commit 0f11ff6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

codechecker_common/compatibility/multiprocessing.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
# pylint: disable=no-name-in-module
1414
# pylint: disable=unused-import
1515
if sys.platform in ["darwin", "win32"]:
16-
from multiprocess import Pool # type: ignore
16+
from multiprocess.pool import Pool as MultiprocessPool
1717
from multiprocess import cpu_count
18+
19+
# Shim class intended to provide API compatibility between the
20+
# pools from multiprocess and concurrent.futures.
21+
class Pool(MultiprocessPool):
22+
def __init__(self, *args, max_workers=None, **kwargs):
23+
super().__init__(*args, processes=max_workers, **kwargs)
1824
else:
1925
from concurrent.futures import ProcessPoolExecutor as Pool # type: ignore
2026
from multiprocessing import cpu_count

0 commit comments

Comments
 (0)