worker: remove Python 2 support code
authorGregory Szorc <gregory.szorc@gmail.com>
Mon, 21 Feb 2022 10:39:48 -0700
changeset 48901 cc0e059d2af8
parent 48900 5ed68dc64948
child 48902 1ba11c8f3430
worker: remove Python 2 support code Differential Revision: https://phab.mercurial-scm.org/D12304
mercurial/worker.py
--- a/mercurial/worker.py	Mon Feb 21 10:39:09 2022 -0700
+++ b/mercurial/worker.py	Mon Feb 21 10:39:48 2022 -0700
@@ -64,51 +64,39 @@
     return min(max(countcpus(), 4), 32)
 
 
-if pycompat.ispy3:
-
-    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.
-
-        def readline(self):
-            return self._wrapped.readline()
-
-        # issue multiple reads until size is fulfilled
-        def read(self, size=-1):
-            if size < 0:
-                return self._wrapped.readall()
-
-            buf = bytearray(size)
-            view = memoryview(buf)
-            pos = 0
-
-            while pos < size:
-                ret = self._wrapped.readinto(view[pos:])
-                if not ret:
-                    break
-                pos += ret
-
-            del view
-            del buf[pos:]
-            return bytes(buf)
+def ismainthread():
+    return threading.current_thread() == threading.main_thread()
 
 
-else:
+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.
+
+    def readline(self):
+        return self._wrapped.readline()
 
-    def ismainthread():
-        # pytype: disable=module-attr
-        return isinstance(threading.current_thread(), threading._MainThread)
-        # pytype: enable=module-attr
+    # issue multiple reads until size is fulfilled
+    def read(self, size=-1):
+        if size < 0:
+            return self._wrapped.readall()
+
+        buf = bytearray(size)
+        view = memoryview(buf)
+        pos = 0
 
-    def _blockingreader(wrapped):
-        return wrapped
+        while pos < size:
+            ret = self._wrapped.readinto(view[pos:])
+            if not ret:
+                break
+            pos += ret
+
+        del view
+        del buf[pos:]
+        return bytes(buf)
 
 
 if pycompat.isposix or pycompat.iswindows: