Don't redraw the screen more often than necessary.

This commit is contained in:
Aldo Cortesi 2011-06-27 14:01:08 +12:00
parent b04d074341
commit 2ae7808ca9
3 changed files with 11 additions and 4 deletions

View File

@ -1306,14 +1306,18 @@ class ConsoleMaster(flow.FlowMaster):
return size
def loop(self):
changed = True
try:
while not controller.exit:
startloop = time.time()
self.statusbar.redraw()
size = self.drawscreen()
self.tick(self.masterq)
if changed:
self.statusbar.redraw()
size = self.drawscreen()
changed = self.tick(self.masterq)
self.ui.set_input_timeouts(max_wait=0.1)
keys = self.ui.get_input()
if keys:
changed = True
for k in keys:
if self.prompting:
if k == "esc":

View File

@ -65,6 +65,7 @@ class Master:
self.masterq = Queue.Queue()
def tick(self, q):
changed = False
try:
# This endless loop runs until the 'Queue.Empty'
# exception is thrown. If more than one request is in
@ -74,8 +75,10 @@ class Master:
# Small timeout to prevent pegging the CPU
msg = q.get(timeout=0.01)
self.handle(msg)
changed = True
except Queue.Empty:
pass
return changed
def run(self):
if self.server:

View File

@ -540,7 +540,7 @@ class FlowMaster(controller.Master):
if self.server_playback.exit and self.server_playback.count() == 0:
self.shutdown()
controller.Master.tick(self, q)
return controller.Master.tick(self, q)
def load_flows(self, fr):
"""