1 |
commit: 3888e16314afa9107aa0f2d9dce864b85246822c |
2 |
Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Feb 16 06:17:12 2019 +0000 |
4 |
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Feb 16 06:17:12 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=3888e163 |
7 |
|
8 |
Replace multiprocessing.cpu_count with portage.util.cpuinfo.get_cpu_count |
9 |
|
10 |
portage.util.cpuinfo.get_cpu_count was only used in one spot before, and |
11 |
other call-sites just used multiprocessing.cpu_count() directly. |
12 |
|
13 |
Replace all multiprocessing.cpu_count() calls with get_cpu_count() in |
14 |
portage.util.cpuinfo, to ensure consistency in CPU calculation. |
15 |
|
16 |
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org> |
17 |
|
18 |
lib/portage/dbapi/porttree.py | 4 ++-- |
19 |
lib/portage/util/futures/executor/fork.py | 4 ++-- |
20 |
lib/portage/util/futures/iter_completed.py | 18 +++++++++--------- |
21 |
3 files changed, 13 insertions(+), 13 deletions(-) |
22 |
|
23 |
diff --git a/lib/portage/dbapi/porttree.py b/lib/portage/dbapi/porttree.py |
24 |
index 2ff3e1b34..64a5f3681 100644 |
25 |
--- a/lib/portage/dbapi/porttree.py |
26 |
+++ b/lib/portage/dbapi/porttree.py |
27 |
@@ -1471,11 +1471,11 @@ def _async_manifest_fetchlist(portdb, repo_config, cp, cpv_list=None, |
28 |
@param cpv_list: list of ebuild cpv values for a Manifest |
29 |
@type cpv_list: list |
30 |
@param max_jobs: max number of futures to process concurrently (default |
31 |
- is multiprocessing.cpu_count()) |
32 |
+ is portage.util.cpuinfo.get_cpu_count()) |
33 |
@type max_jobs: int |
34 |
@param max_load: max load allowed when scheduling a new future, |
35 |
otherwise schedule no more than 1 future at a time (default |
36 |
- is multiprocessing.cpu_count()) |
37 |
+ is portage.util.cpuinfo.get_cpu_count()) |
38 |
@type max_load: int or float |
39 |
@param loop: event loop |
40 |
@type loop: EventLoop |
41 |
|
42 |
diff --git a/lib/portage/util/futures/executor/fork.py b/lib/portage/util/futures/executor/fork.py |
43 |
index 72844403c..add7b3c9e 100644 |
44 |
--- a/lib/portage/util/futures/executor/fork.py |
45 |
+++ b/lib/portage/util/futures/executor/fork.py |
46 |
@@ -7,13 +7,13 @@ __all__ = ( |
47 |
|
48 |
import collections |
49 |
import functools |
50 |
-import multiprocessing |
51 |
import os |
52 |
import sys |
53 |
import traceback |
54 |
|
55 |
from portage.util._async.AsyncFunction import AsyncFunction |
56 |
from portage.util.futures import asyncio |
57 |
+from portage.util.cpuinfo import get_cpu_count |
58 |
|
59 |
|
60 |
class ForkExecutor(object): |
61 |
@@ -24,7 +24,7 @@ class ForkExecutor(object): |
62 |
This is entirely driven by an event loop. |
63 |
""" |
64 |
def __init__(self, max_workers=None, loop=None): |
65 |
- self._max_workers = max_workers or multiprocessing.cpu_count() |
66 |
+ self._max_workers = max_workers or get_cpu_count() |
67 |
self._loop = asyncio._wrap_loop(loop) |
68 |
self._submit_queue = collections.deque() |
69 |
self._running_tasks = {} |
70 |
|
71 |
diff --git a/lib/portage/util/futures/iter_completed.py b/lib/portage/util/futures/iter_completed.py |
72 |
index 31b5e0c78..4c48ea0fe 100644 |
73 |
--- a/lib/portage/util/futures/iter_completed.py |
74 |
+++ b/lib/portage/util/futures/iter_completed.py |
75 |
@@ -2,11 +2,11 @@ |
76 |
# Distributed under the terms of the GNU General Public License v2 |
77 |
|
78 |
import functools |
79 |
-import multiprocessing |
80 |
|
81 |
from portage.util._async.AsyncTaskFuture import AsyncTaskFuture |
82 |
from portage.util._async.TaskScheduler import TaskScheduler |
83 |
from portage.util.futures import asyncio |
84 |
+from portage.util.cpuinfo import get_cpu_count |
85 |
|
86 |
|
87 |
def iter_completed(futures, max_jobs=None, max_load=None, loop=None): |
88 |
@@ -18,11 +18,11 @@ def iter_completed(futures, max_jobs=None, max_load=None, loop=None): |
89 |
@param futures: iterator of asyncio.Future (or compatible) |
90 |
@type futures: iterator |
91 |
@param max_jobs: max number of futures to process concurrently (default |
92 |
- is multiprocessing.cpu_count()) |
93 |
+ is portage.util.cpuinfo.get_cpu_count()) |
94 |
@type max_jobs: int |
95 |
@param max_load: max load allowed when scheduling a new future, |
96 |
otherwise schedule no more than 1 future at a time (default |
97 |
- is multiprocessing.cpu_count()) |
98 |
+ is portage.util.cpuinfo.get_cpu_count()) |
99 |
@type max_load: int or float |
100 |
@param loop: event loop |
101 |
@type loop: EventLoop |
102 |
@@ -47,11 +47,11 @@ def async_iter_completed(futures, max_jobs=None, max_load=None, loop=None): |
103 |
@param futures: iterator of asyncio.Future (or compatible) |
104 |
@type futures: iterator |
105 |
@param max_jobs: max number of futures to process concurrently (default |
106 |
- is multiprocessing.cpu_count()) |
107 |
+ is portage.util.cpuinfo.get_cpu_count()) |
108 |
@type max_jobs: int |
109 |
@param max_load: max load allowed when scheduling a new future, |
110 |
otherwise schedule no more than 1 future at a time (default |
111 |
- is multiprocessing.cpu_count()) |
112 |
+ is portage.util.cpuinfo.get_cpu_count()) |
113 |
@type max_load: int or float |
114 |
@param loop: event loop |
115 |
@type loop: EventLoop |
116 |
@@ -61,8 +61,8 @@ def async_iter_completed(futures, max_jobs=None, max_load=None, loop=None): |
117 |
""" |
118 |
loop = asyncio._wrap_loop(loop) |
119 |
|
120 |
- max_jobs = max_jobs or multiprocessing.cpu_count() |
121 |
- max_load = max_load or multiprocessing.cpu_count() |
122 |
+ max_jobs = max_jobs or portage.util.cpuinfo.get_cpu_count() |
123 |
+ max_load = max_load or portage.util.cpuinfo.get_cpu_count() |
124 |
|
125 |
future_map = {} |
126 |
def task_generator(): |
127 |
@@ -120,11 +120,11 @@ def iter_gather(futures, max_jobs=None, max_load=None, loop=None): |
128 |
@param futures: iterator of asyncio.Future (or compatible) |
129 |
@type futures: iterator |
130 |
@param max_jobs: max number of futures to process concurrently (default |
131 |
- is multiprocessing.cpu_count()) |
132 |
+ is portage.util.cpuinfo.get_cpu_count()) |
133 |
@type max_jobs: int |
134 |
@param max_load: max load allowed when scheduling a new future, |
135 |
otherwise schedule no more than 1 future at a time (default |
136 |
- is multiprocessing.cpu_count()) |
137 |
+ is portage.util.cpuinfo.get_cpu_count()) |
138 |
@type max_load: int or float |
139 |
@param loop: event loop |
140 |
@type loop: EventLoop |