Show More
@@ -11,6 +11,7 b' import errno' | |||
|
11 | 11 | import os |
|
12 | 12 | import signal |
|
13 | 13 | import sys |
|
14 | import threading | |
|
14 | 15 | |
|
15 | 16 | from .i18n import _ |
|
16 | 17 | from . import ( |
@@ -53,7 +54,7 b' def _numworkers(ui):' | |||
|
53 | 54 | raise error.Abort(_('number of cpus must be an integer')) |
|
54 | 55 | return min(max(countcpus(), 4), 32) |
|
55 | 56 | |
|
56 | if pycompat.isposix: | |
|
57 | if pycompat.isposix or pycompat.iswindows: | |
|
57 | 58 | _startupcost = 0.01 |
|
58 | 59 | else: |
|
59 | 60 | _startupcost = 1e30 |
@@ -203,7 +204,51 b' def _posixexitstatus(code):' | |||
|
203 | 204 | elif os.WIFSIGNALED(code): |
|
204 | 205 | return -os.WTERMSIG(code) |
|
205 | 206 | |
|
206 | if not pycompat.iswindows: | |
|
207 | def _windowsworker(ui, func, staticargs, args): | |
|
208 | class Worker(threading.Thread): | |
|
209 | def __init__(self, taskqueue, resultqueue, func, staticargs, | |
|
210 | group=None, target=None, name=None, verbose=None): | |
|
211 | threading.Thread.__init__(self, group=group, target=target, | |
|
212 | name=name, verbose=verbose) | |
|
213 | self._taskqueue = taskqueue | |
|
214 | self._resultqueue = resultqueue | |
|
215 | self._func = func | |
|
216 | self._staticargs = staticargs | |
|
217 | ||
|
218 | def run(self): | |
|
219 | while not self._taskqueue.empty(): | |
|
220 | try: | |
|
221 | args = self._taskqueue.get_nowait() | |
|
222 | for res in self._func(*self._staticargs + (args,)): | |
|
223 | self._resultqueue.put(res) | |
|
224 | except util.empty: | |
|
225 | break | |
|
226 | ||
|
227 | workers = _numworkers(ui) | |
|
228 | threads = [] | |
|
229 | resultqueue = util.queue() | |
|
230 | taskqueue = util.queue() | |
|
231 | # partition work to more pieces than workers to minimize the chance | |
|
232 | # of uneven distribution of large tasks between the workers | |
|
233 | for pargs in partition(args, workers * 20): | |
|
234 | taskqueue.put(pargs) | |
|
235 | for _i in range(workers): | |
|
236 | t = Worker(taskqueue, resultqueue, func, staticargs) | |
|
237 | threads.append(t) | |
|
238 | t.start() | |
|
239 | while any(t.is_alive() for t in threads): | |
|
240 | while not resultqueue.empty(): | |
|
241 | yield resultqueue.get() | |
|
242 | t = threads[0] | |
|
243 | t.join(0.05) | |
|
244 | if not t.is_alive(): | |
|
245 | threads.remove(t) | |
|
246 | while not resultqueue.empty(): | |
|
247 | yield resultqueue.get() | |
|
248 | ||
|
249 | if pycompat.iswindows: | |
|
250 | _platformworker = _windowsworker | |
|
251 | else: | |
|
207 | 252 | _platformworker = _posixworker |
|
208 | 253 | _exitstatus = _posixexitstatus |
|
209 | 254 |
General Comments 0
You need to be logged in to leave comments.
Login now