changeset 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 d159d0fafa78
children 012e25abc603
files mercurial/worker.py
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/worker.py	Fri Jan 08 21:47:31 2021 +0530
+++ b/mercurial/worker.py	Mon Dec 28 01:05:09 2020 +0100
@@ -67,6 +67,9 @@
 
 if pycompat.ispy3:
 
+    def ismainthread():
+        return threading.current_thread() == threading.main_thread()
+
     class _blockingreader(object):
         def __init__(self, wrapped):
             self._wrapped = wrapped
@@ -100,6 +103,9 @@
 
 else:
 
+    def ismainthread():
+        return isinstance(threading.current_thread(), threading._MainThread)
+
     def _blockingreader(wrapped):
         return wrapped
 
@@ -155,6 +161,11 @@
     release the GIL.
     """
     enabled = ui.configbool(b'worker', b'enabled')
+    if enabled and _platformworker is _posixworker and not ismainthread():
+        # The POSIX worker has to install a handler for SIGCHLD.
+        # Python up to 3.9 only allows this in the main thread.
+        enabled = False
+
     if enabled and worthwhile(ui, costperarg, len(args), threadsafe=threadsafe):
         return _platformworker(ui, func, staticargs, args, hasretval)
     return func(*staticargs + (args,))