##// END OF EJS Templates
worker: remove Python 2 support code...
Gregory Szorc -
r49756:cc0e059d default
parent child Browse files
Show More
@@ -64,51 +64,39 b' def _numworkers(ui):'
64 64 return min(max(countcpus(), 4), 32)
65 65
66 66
67 if pycompat.ispy3:
68
69 def ismainthread():
70 return threading.current_thread() == threading.main_thread()
71
72 class _blockingreader(object):
73 def __init__(self, wrapped):
74 self._wrapped = wrapped
75
76 # Do NOT implement readinto() by making it delegate to
77 # _wrapped.readinto(), since that is unbuffered. The unpickler is fine
78 # with just read() and readline(), so we don't need to implement it.
79
80 def readline(self):
81 return self._wrapped.readline()
82
83 # issue multiple reads until size is fulfilled
84 def read(self, size=-1):
85 if size < 0:
86 return self._wrapped.readall()
87
88 buf = bytearray(size)
89 view = memoryview(buf)
90 pos = 0
91
92 while pos < size:
93 ret = self._wrapped.readinto(view[pos:])
94 if not ret:
95 break
96 pos += ret
97
98 del view
99 del buf[pos:]
100 return bytes(buf)
67 def ismainthread():
68 return threading.current_thread() == threading.main_thread()
101 69
102 70
103 else:
71 class _blockingreader(object):
72 def __init__(self, wrapped):
73 self._wrapped = wrapped
74
75 # Do NOT implement readinto() by making it delegate to
76 # _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
79 def readline(self):
80 return self._wrapped.readline()
104 81
105 def ismainthread():
106 # pytype: disable=module-attr
107 return isinstance(threading.current_thread(), threading._MainThread)
108 # pytype: enable=module-attr
82 # issue multiple reads until size is fulfilled
83 def read(self, size=-1):
84 if size < 0:
85 return self._wrapped.readall()
86
87 buf = bytearray(size)
88 view = memoryview(buf)
89 pos = 0
109 90
110 def _blockingreader(wrapped):
111 return wrapped
91 while pos < size:
92 ret = self._wrapped.readinto(view[pos:])
93 if not ret:
94 break
95 pos += ret
96
97 del view
98 del buf[pos:]
99 return bytes(buf)
112 100
113 101
114 102 if pycompat.isposix or pycompat.iswindows:
General Comments 0
You need to be logged in to leave comments. Login now