Mercurial > public > mercurial-scm > hg
comparison mercurial/worker.py @ 46240:a42502e9ae6d
worker: POSIX only supports workers from main thread (issue6460)
The POSIX backend sets signal handlers for SIGINT (maybe avoidable) and
SIGCHLD (necessary for waitpid). Python up to 3.9 only allow this from
the main thread, so disable the worker feature otherwise.
Differential Revision: https://phab.mercurial-scm.org/D9660
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Mon, 28 Dec 2020 01:05:09 +0100 |
parents | 89a2afe31e82 |
children | f64806207752 |
comparison
equal
deleted
inserted
replaced
46239:d159d0fafa78 | 46240:a42502e9ae6d |
---|---|
65 return min(max(countcpus(), 4), 32) | 65 return min(max(countcpus(), 4), 32) |
66 | 66 |
67 | 67 |
68 if pycompat.ispy3: | 68 if pycompat.ispy3: |
69 | 69 |
70 def ismainthread(): | |
71 return threading.current_thread() == threading.main_thread() | |
72 | |
70 class _blockingreader(object): | 73 class _blockingreader(object): |
71 def __init__(self, wrapped): | 74 def __init__(self, wrapped): |
72 self._wrapped = wrapped | 75 self._wrapped = wrapped |
73 | 76 |
74 # Do NOT implement readinto() by making it delegate to | 77 # Do NOT implement readinto() by making it delegate to |
97 del buf[pos:] | 100 del buf[pos:] |
98 return bytes(buf) | 101 return bytes(buf) |
99 | 102 |
100 | 103 |
101 else: | 104 else: |
105 | |
106 def ismainthread(): | |
107 return isinstance(threading.current_thread(), threading._MainThread) | |
102 | 108 |
103 def _blockingreader(wrapped): | 109 def _blockingreader(wrapped): |
104 return wrapped | 110 return wrapped |
105 | 111 |
106 | 112 |
153 threadsafe - whether work items are thread safe and can be executed using | 159 threadsafe - whether work items are thread safe and can be executed using |
154 a thread-based worker. Should be disabled for CPU heavy tasks that don't | 160 a thread-based worker. Should be disabled for CPU heavy tasks that don't |
155 release the GIL. | 161 release the GIL. |
156 """ | 162 """ |
157 enabled = ui.configbool(b'worker', b'enabled') | 163 enabled = ui.configbool(b'worker', b'enabled') |
164 if enabled and _platformworker is _posixworker and not ismainthread(): | |
165 # The POSIX worker has to install a handler for SIGCHLD. | |
166 # Python up to 3.9 only allows this in the main thread. | |
167 enabled = False | |
168 | |
158 if enabled and worthwhile(ui, costperarg, len(args), threadsafe=threadsafe): | 169 if enabled and worthwhile(ui, costperarg, len(args), threadsafe=threadsafe): |
159 return _platformworker(ui, func, staticargs, args, hasretval) | 170 return _platformworker(ui, func, staticargs, args, hasretval) |
160 return func(*staticargs + (args,)) | 171 return func(*staticargs + (args,)) |
161 | 172 |
162 | 173 |