D12304: worker: remove Python 2 support code
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Wed Mar 2 23:31:31 UTC 2022
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
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:
To: indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list