Permalink
Browse files

reduce cpu-usage when display stream returned by knife solo command

  • Loading branch information...
amazedkoumei committed Apr 15, 2013
1 parent cc1d6cd commit c6ea1ac40c2679cf78555e36de726216309e4803
Showing with 21 additions and 11 deletions.
  1. +14 −5 SublimeKnifeSolo.py
  2. +7 −6 helper.py
View
@@ -85,19 +85,28 @@ def runKnife(process, messageManager):
stderr_reader.start()
while not stdout_reader.eof() or not stderr_reader.eof():
stdout = ""
while not stdout_queue.empty():
sublime.set_timeout(lambda:messageManager.write(stdout_queue.get()), 0)
time.sleep(.1)
stdout += stdout_queue.get()
else:
sublime.set_timeout(lambda:messageManager.write(stdout), 0)
time.sleep(.5)
stderr = ""
while not stderr_queue.empty():
sublime.set_timeout(lambda:messageManager.write(stderr_queue.get()), 0)
time.sleep(.1)
stderr += stderr_queue.get()
else:
sublime.set_timeout(lambda:messageManager.write(stderr), 0)
time.sleep(.5)
time.sleep(.5)
stdout_reader.join()
stderr_reader.join()
process.stdout.close()
process.stderr.close()
sublime.set_timeout(lambda:messageManager.write(u"\n\n\n\n\nFINISH!!!"), 0)
sublime.set_timeout(lambda:messageManager.write(u"\n\nfinished\n\n"), 0)
def getEncoding(str):
for encoding in ['utf-8', 'shift-jis', 'euc-jp']:
View
@@ -40,14 +40,15 @@ def showPanel(self):
self.window.run_command('show_panel', {'panel': 'output.' + self.panelName})
def write(self, text):
self.view.set_read_only(False)
edit = self.view.begin_edit()
self.view.insert(edit, self.view.size(), text)
self.view.end_edit(edit)
self.view.set_read_only(True)
try:
self.view.insert(edit, self.view.size(), text)
finally:
self.view.end_edit(edit)
self.scroll()
self.scroll()
#self.view.show(self.view.size())
def scroll(self):
(cur_row, _) = self.view.rowcol(self.view.size())
self.view.show(self.view.text_point(cur_row, 0))
self.view.show(self.view.text_point(cur_row, 0))

0 comments on commit c6ea1ac

Please sign in to comment.