[tor-commits] [nyx/master] Consolidate redraws if unable to draw for a while

atagar at torproject.org atagar at torproject.org
Wed Nov 1 19:16:56 UTC 2017


commit 2c8c116da8cffa9e437fdcc04ca77031d2a2672e
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Nov 1 12:07:34 2017 -0700

    Consolidate redraws if unable to draw for a while
    
    When the menu's open for a while we block the graph panel from redrawing
    itself, causing events to accumilate. Then when the menu's closed we perform
    a flurry of updates which makes the graph appear to catch up in fast forward.
    
    Instead, if a panel is unable to draw itself after a second it gives up the
    redraw attempt. This way when the menu's closed we perform just a single redraw
    that catches us up.
    
    Caught thanks to Guinness on tor-relays at .
---
 nyx/curses.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/nyx/curses.py b/nyx/curses.py
index 349572e..976f625 100644
--- a/nyx/curses.py
+++ b/nyx/curses.py
@@ -92,6 +92,7 @@ import functools
 import os
 import re
 import threading
+import time
 
 import stem.util.conf
 import stem.util.enum
@@ -709,7 +710,15 @@ def draw(func, left = 0, top = 0, width = None, height = None, background = None
   :returns: :class:`~nyx.curses.Dimension` for the space we drew within
   """
 
-  with CURSES_LOCK:
+  start = time.time()
+
+  while not CURSES_LOCK.acquire(False):
+    if (time.time() - start) > 1:
+      return  # if we've been blocked from drawing for a full second then abort
+
+    time.sleep(0.05)
+
+  try:
     if HALT_ACTIVITY:
       return
 
@@ -738,6 +747,8 @@ def draw(func, left = 0, top = 0, width = None, height = None, background = None
     curses_subwindow.refresh()
 
     return subwindow_dimensions
+  finally:
+    CURSES_LOCK.release()
 
 
 class _Subwindow(object):



More information about the tor-commits mailing list