Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

thread: improve output performance with buffer

Changeset 1e721a9b4dbd

Parent e3eccbb85523

by Yuki KODAMA

Changes to one file · Browse files at 1e721a9b4dbd Showing diff from parent e3eccbb85523 Diff from another changeset...

 
11
12
13
14
 
15
16
17
 
47
48
49
50
51
52
 
 
53
54
55
 
124
125
126
127
 
128
129
130
 
141
142
143
144
 
145
146
147
 
150
151
152
 
 
153
154
155
156
157
158
 
159
160
161
 
164
165
166
 
167
168
169
170
171
172
 
 
 
 
 
173
 
174
175
 
 
 
 
 
 
 
 
 
 
 
 
 
176
177
178
 
11
12
13
 
14
15
16
17
 
47
48
49
 
 
 
50
51
52
53
54
 
123
124
125
 
126
127
128
129
 
140
141
142
 
143
144
145
146
 
149
150
151
152
153
154
155
156
157
 
 
158
159
160
161
 
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
@@ -11,7 +11,7 @@
 import time  import urllib2   -from PyQt4.QtCore import SIGNAL, pyqtSignal, QObject, QThread +from PyQt4.QtCore import SIGNAL, pyqtSignal, QObject, QThread, QTimer  from PyQt4.QtGui import QMessageBox, QInputDialog, QLineEdit    from mercurial import ui, util, error, dispatch @@ -47,9 +47,8 @@
  if self._buffers:   self._buffers[-1].extend([str(a) for a in args])   else: - for a in args: - data = DataWrapper((str(a), opts.get('label', ''))) - self.sig.emit(SIG_OUTPUT, data) + wrapper = DataWrapper((''.join(args), opts.get('label', ''))) + self.sig.emit(SIG_OUTPUT, wrapper)     def write_err(self, *args, **opts):   for a in args: @@ -124,7 +123,7 @@
  # (msg=str, label=str) [wrapped]   outputReceived = pyqtSignal(DataWrapper)   - # msg=str [wrapped] + # (msg=str, label=str) [wrapped]   errorReceived = pyqtSignal(DataWrapper)     # (msg=str, password=bool, choices=tuple, default=str) [wrapped] @@ -141,7 +140,7 @@
  # others - return code of command   commandFinished = pyqtSignal(DataWrapper)   - def __init__(self, cmdline, parent=None): + def __init__(self, cmdline, parent=None, buffering=True):   super(CmdThread, self).__init__()     self.cmdline = cmdline @@ -150,12 +149,13 @@
  self.abortbyuser = False   self.responseq = Queue.Queue()   self.ui = QtUi(responseq=self.responseq) + self.buffering = buffering + self.buffer = []     # Re-emit all ui.sig's signals to CmdThread (self).   # QSignalMapper doesn't help for this since our SIGNAL   # parameters contain 'PyQt_PyObject' types. - for name, sig in ((SIG_OUTPUT, self.outputReceived), - (SIG_ERROR, self.errorReceived), + for name, sig in ((SIG_ERROR, self.errorReceived),   (SIG_INTERACT, self.interactReceived),   (SIG_PROGRESS, self.progressReceived)):   def repeater(sig): # hide 'sig' local variable name @@ -164,15 +164,35 @@
    self.finished.connect(self.thread_finished)   self.interactReceived.connect(self.interact_handler) + self.connect(self.ui.sig, SIG_OUTPUT, self.output_handler)     def abort(self):   if self.isRunning() and hasattr(self, 'thread_id'):   self.abortbyuser = True   thread2._async_raise(self.thread_id, KeyboardInterrupt)   + def flush(self): + for item in self.buffer: + self.outputReceived.emit(item) + self.buffer = [] +   def thread_finished(self): + self.flush()   self.commandFinished.emit(DataWrapper(self.ret))   + def output_handler(self, wrapper): + if self.buffering: + if len(self.buffer) > 0: + last = self.buffer.pop() + if last.data[1] == wrapper.data[1]: + wrapper = DataWrapper((last.data[0] + wrapper.data[0], + last.data[1])) + else: + QTimer.singleShot(20, self.flush) + self.buffer.append(wrapper) + else: + self.outputReceived.emit(wrapper) +   def interact_handler(self, wrapper):   prompt, password, choices, default = wrapper.data   prompt = hglib.tounicode(prompt)