Patchwork D9660: worker: restrict use of worker procesess to the main thread

login
register
mail settings
Submitter phabricator
Date Dec. 28, 2020, 12:05 a.m.
Message ID <differential-rev-PHID-DREV-5npgjrqcsa7gvuzjjtxr-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47971/
State Superseded
Headers show

Comments

phabricator - Dec. 28, 2020, 12:05 a.m.
joerg.sonnenberger created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is a test workaround for bz6460

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9660

AFFECTED FILES
  mercurial/worker.py

CHANGE DETAILS




To: joerg.sonnenberger, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -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
 
@@ -154,7 +160,7 @@ 
     a thread-based worker. Should be disabled for CPU heavy tasks that don't
     release the GIL.
     """
-    enabled = ui.configbool(b'worker', b'enabled')
+    enabled = ui.configbool(b'worker', b'enabled') and ismainthread()
     if enabled and worthwhile(ui, costperarg, len(args), threadsafe=threadsafe):
         return _platformworker(ui, func, staticargs, args, hasretval)
     return func(*staticargs + (args,))