comparison mercurial/worker.py @ 43077:687b865b95ad

formatting: byteify all mercurial/ and hgext/ string literals Done with python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py') black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**') # skip-blame mass-reformatting only Differential Revision: https://phab.mercurial-scm.org/D6972
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:48:39 -0400
parents 2372284d9457
children 9f70512ae2cf
comparison
equal deleted inserted replaced
43076:2372284d9457 43077:687b865b95ad
42 except (AttributeError, ValueError): 42 except (AttributeError, ValueError):
43 pass 43 pass
44 44
45 # windows 45 # windows
46 try: 46 try:
47 n = int(encoding.environ['NUMBER_OF_PROCESSORS']) 47 n = int(encoding.environ[b'NUMBER_OF_PROCESSORS'])
48 if n > 0: 48 if n > 0:
49 return n 49 return n
50 except (KeyError, ValueError): 50 except (KeyError, ValueError):
51 pass 51 pass
52 52
53 return 1 53 return 1
54 54
55 55
56 def _numworkers(ui): 56 def _numworkers(ui):
57 s = ui.config('worker', 'numcpus') 57 s = ui.config(b'worker', b'numcpus')
58 if s: 58 if s:
59 try: 59 try:
60 n = int(s) 60 n = int(s)
61 if n >= 1: 61 if n >= 1:
62 return n 62 return n
63 except ValueError: 63 except ValueError:
64 raise error.Abort(_('number of cpus must be an integer')) 64 raise error.Abort(_(b'number of cpus must be an integer'))
65 return min(max(countcpus(), 4), 32) 65 return min(max(countcpus(), 4), 32)
66 66
67 67
68 if pycompat.isposix or pycompat.iswindows: 68 if pycompat.isposix or pycompat.iswindows:
69 _STARTUP_COST = 0.01 69 _STARTUP_COST = 0.01
113 113
114 threadsafe - whether work items are thread safe and can be executed using 114 threadsafe - whether work items are thread safe and can be executed using
115 a thread-based worker. Should be disabled for CPU heavy tasks that don't 115 a thread-based worker. Should be disabled for CPU heavy tasks that don't
116 release the GIL. 116 release the GIL.
117 ''' 117 '''
118 enabled = ui.configbool('worker', 'enabled') 118 enabled = ui.configbool(b'worker', b'enabled')
119 if enabled and worthwhile(ui, costperarg, len(args), threadsafe=threadsafe): 119 if enabled and worthwhile(ui, costperarg, len(args), threadsafe=threadsafe):
120 return _platformworker(ui, func, staticargs, args, hasretval) 120 return _platformworker(ui, func, staticargs, args, hasretval)
121 return func(*staticargs + (args,)) 121 return func(*staticargs + (args,))
122 122
123 123
329 # important to surface the inital exception than the 329 # important to surface the inital exception than the
330 # fact that one of workers may be processing a large 330 # fact that one of workers may be processing a large
331 # task and does not get to handle the interruption. 331 # task and does not get to handle the interruption.
332 ui.warn( 332 ui.warn(
333 _( 333 _(
334 "failed to kill worker threads while " 334 b"failed to kill worker threads while "
335 "handling an exception\n" 335 b"handling an exception\n"
336 ) 336 )
337 ) 337 )
338 return 338 return
339 339
340 workers = _numworkers(ui) 340 workers = _numworkers(ui)