[tor-commits] [nyx/master] Moving HALT_ACTIVITY to curses module

atagar at torproject.org atagar at torproject.org
Fri Jul 15 17:33:39 UTC 2016


commit 03820fcafbd30b8209e8aeadb3b68d6e0b330e1f
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Jul 15 08:57:19 2016 -0700

    Moving HALT_ACTIVITY to curses module
    
    Flag is for preventing further curses activity so this is where it belongs.
    Expanding it to cover get_str() (... maybe that's why I've occasionally had nyx
    freeze?) and be covered by the curses lock.
---
 nyx/curses.py         | 19 +++++++++++++++++++
 nyx/panel/__init__.py |  8 ++------
 nyx/starter.py        |  3 +--
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/nyx/curses.py b/nyx/curses.py
index ed8b87b..6e605a7 100644
--- a/nyx/curses.py
+++ b/nyx/curses.py
@@ -18,6 +18,7 @@ if we want Windows support in the future too.
   curses_attr - curses encoded text attribute
   screen_size - provides the dimensions of our screen
   screenshot - dump of the present on-screen content
+  halt - prevents further curses rendering during shutdown
 
   is_color_supported - checks if terminal supports color output
   get_color_override - provides color we override requests with
@@ -99,6 +100,7 @@ from nyx import msg, log
 
 CURSES_SCREEN = None
 CURSES_LOCK = threading.RLock()
+HALT_ACTIVITY = False
 
 # Text colors and attributes. These are *very* commonly used so including
 # shorter aliases (so they can be referenced as just GREEN or BOLD).
@@ -283,6 +285,9 @@ def str_input(x, y, initial_text = ''):
       return key
 
   with CURSES_LOCK:
+    if HALT_ACTIVITY:
+      return None
+
     try:
       curses.curs_set(1)  # show cursor
     except curses.error:
@@ -354,6 +359,17 @@ def screenshot():
   return '\n'.join(lines).rstrip()
 
 
+def halt():
+  """
+  Prevents further rendering of curses content while python's shutting down.
+  """
+
+  global HALT_ACTIVITY
+
+  with CURSES_LOCK:
+    HALT_ACTIVITY = True
+
+
 def is_color_supported():
   """
   Checks if curses currently supports rendering colors.
@@ -497,6 +513,9 @@ def draw(func, left = 0, top = 0, width = None, height = None, background = None
   """
 
   with CURSES_LOCK:
+    if HALT_ACTIVITY:
+      return
+
     dimensions = screen_size()
     subwindow_width = max(0, dimensions.width - left)
     subwindow_height = max(0, dimensions.height - top)
diff --git a/nyx/panel/__init__.py b/nyx/panel/__init__.py
index b572d66..96a39bd 100644
--- a/nyx/panel/__init__.py
+++ b/nyx/panel/__init__.py
@@ -21,8 +21,6 @@ __all__ = [
   'torrc',
 ]
 
-HALT_ACTIVITY = False  # prevents curses redraws if set
-
 
 class KeyHandler(collections.namedtuple('Help', ['key', 'description', 'current'])):
   """
@@ -157,10 +155,8 @@ class Panel(object):
     able (ie, the subwindow's unchanged), instead just refreshing the display.
     """
 
-    # skipped if not currently visible or activity has been halted
-
-    if not self._visible or HALT_ACTIVITY:
-      return
+    if not self._visible:
+      return  # not currently visible
 
     nyx.curses.draw(self.draw, top = self._top, height = self.get_height())
 
diff --git a/nyx/starter.py b/nyx/starter.py
index b9df29a..5f89526 100644
--- a/nyx/starter.py
+++ b/nyx/starter.py
@@ -18,7 +18,6 @@ import nyx
 import nyx.arguments
 import nyx.controller
 import nyx.curses
-import nyx.panel
 import nyx.tracker
 
 import stem
@@ -95,7 +94,7 @@ def main(config):
   except KeyboardInterrupt:
     pass  # skip printing a stack trace
   finally:
-    nyx.panel.HALT_ACTIVITY = True
+    nyx.curses.halt()
     _shutdown_daemons(controller)
 
 





More information about the tor-commits mailing list