Mercurial > hg
comparison mercurial/worker.py @ 48901:cc0e059d2af8
worker: remove Python 2 support code
Differential Revision: https://phab.mercurial-scm.org/D12304
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 21 Feb 2022 10:39:48 -0700 |
parents | 6000f5b25c9b |
children | a0674e916fb6 |
comparison
equal
deleted
inserted
replaced
48900:5ed68dc64948 | 48901:cc0e059d2af8 |
---|---|
62 except ValueError: | 62 except ValueError: |
63 raise error.Abort(_(b'number of cpus must be an integer')) | 63 raise error.Abort(_(b'number of cpus must be an integer')) |
64 return min(max(countcpus(), 4), 32) | 64 return min(max(countcpus(), 4), 32) |
65 | 65 |
66 | 66 |
67 if pycompat.ispy3: | 67 def ismainthread(): |
68 | 68 return threading.current_thread() == threading.main_thread() |
69 def ismainthread(): | 69 |
70 return threading.current_thread() == threading.main_thread() | 70 |
71 | 71 class _blockingreader(object): |
72 class _blockingreader(object): | 72 def __init__(self, wrapped): |
73 def __init__(self, wrapped): | 73 self._wrapped = wrapped |
74 self._wrapped = wrapped | 74 |
75 | 75 # Do NOT implement readinto() by making it delegate to |
76 # Do NOT implement readinto() by making it delegate to | 76 # _wrapped.readinto(), since that is unbuffered. The unpickler is fine |
77 # _wrapped.readinto(), since that is unbuffered. The unpickler is fine | 77 # with just read() and readline(), so we don't need to implement it. |
78 # with just read() and readline(), so we don't need to implement it. | 78 |
79 | 79 def readline(self): |
80 def readline(self): | 80 return self._wrapped.readline() |
81 return self._wrapped.readline() | 81 |
82 | 82 # issue multiple reads until size is fulfilled |
83 # issue multiple reads until size is fulfilled | 83 def read(self, size=-1): |
84 def read(self, size=-1): | 84 if size < 0: |
85 if size < 0: | 85 return self._wrapped.readall() |
86 return self._wrapped.readall() | 86 |
87 | 87 buf = bytearray(size) |
88 buf = bytearray(size) | 88 view = memoryview(buf) |
89 view = memoryview(buf) | 89 pos = 0 |
90 pos = 0 | 90 |
91 | 91 while pos < size: |
92 while pos < size: | 92 ret = self._wrapped.readinto(view[pos:]) |
93 ret = self._wrapped.readinto(view[pos:]) | 93 if not ret: |
94 if not ret: | 94 break |
95 break | 95 pos += ret |
96 pos += ret | 96 |
97 | 97 del view |
98 del view | 98 del buf[pos:] |
99 del buf[pos:] | 99 return bytes(buf) |
100 return bytes(buf) | |
101 | |
102 | |
103 else: | |
104 | |
105 def ismainthread(): | |
106 # pytype: disable=module-attr | |
107 return isinstance(threading.current_thread(), threading._MainThread) | |
108 # pytype: enable=module-attr | |
109 | |
110 def _blockingreader(wrapped): | |
111 return wrapped | |
112 | 100 |
113 | 101 |
114 if pycompat.isposix or pycompat.iswindows: | 102 if pycompat.isposix or pycompat.iswindows: |
115 _STARTUP_COST = 0.01 | 103 _STARTUP_COST = 0.01 |
116 # The Windows worker is thread based. If tasks are CPU bound, threads | 104 # The Windows worker is thread based. If tasks are CPU bound, threads |