Patchwork D12304: worker: remove Python 2 support code

login
register
mail settings
Submitter phabricator
Date March 2, 2022, 11:31 p.m.
Message ID <differential-rev-PHID-DREV-uelomghnfmjvtg4t6cwb-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50641/
State New
Headers show

Comments

phabricator - March 2, 2022, 11:31 p.m.
indygreg created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/worker.py

CHANGE DETAILS




To: indygreg, #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
@@ -64,50 +64,39 @@ 
     return min(max(countcpus(), 4), 32)
 
 
-if pycompat.ispy3:
+def ismainthread():
+    return threading.current_thread() == threading.main_thread()
 
-    def ismainthread():
-        return threading.current_thread() == threading.main_thread()
-
-    class _blockingreader(object):
-        def __init__(self, wrapped):
-            self._wrapped = wrapped
 
-        # Do NOT implement readinto() by making it delegate to
-        # _wrapped.readinto(), since that is unbuffered. The unpickler is fine
-        # with just read() and readline(), so we don't need to implement it.
+class _blockingreader(object):
+    def __init__(self, wrapped):
+        self._wrapped = wrapped
 
-        def readline(self):
-            return self._wrapped.readline()
+    # Do NOT implement readinto() by making it delegate to
+    # _wrapped.readinto(), since that is unbuffered. The unpickler is fine
+    # with just read() and readline(), so we don't need to implement it.
 
-        # issue multiple reads until size is fulfilled
-        def read(self, size=-1):
-            if size < 0:
-                return self._wrapped.readall()
+    def readline(self):
+        return self._wrapped.readline()
 
-            buf = bytearray(size)
-            view = memoryview(buf)
-            pos = 0
+    # issue multiple reads until size is fulfilled
+    def read(self, size=-1):
+        if size < 0:
+            return self._wrapped.readall()
 
-            while pos < size:
-                ret = self._wrapped.readinto(view[pos:])
-                if not ret:
-                    break
-                pos += ret
+        buf = bytearray(size)
+        view = memoryview(buf)
+        pos = 0
 
-            del view
-            del buf[pos:]
-            return bytes(buf)
-
-else:
+        while pos < size:
+            ret = self._wrapped.readinto(view[pos:])
+            if not ret:
+                break
+            pos += ret
 
-    def ismainthread():
-        # pytype: disable=module-attr
-        return isinstance(threading.current_thread(), threading._MainThread)
-        # pytype: enable=module-attr
-
-    def _blockingreader(wrapped):
-        return wrapped
+        del view
+        del buf[pos:]
+        return bytes(buf)
 
 
 if pycompat.isposix or pycompat.iswindows: