[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [nyx/master] Move CURSES_LOCK to nyx.curses



commit b18a2e48f63e2fb15107f2a818f5cc4c0e0688d7
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Wed Mar 16 09:52:38 2016 -0700

    Move CURSES_LOCK to nyx.curses
    
    This belongs with the curses screen. Eventually all curses interactions will go
    through us so nobody outside this module will need the lock.
---
 nyx/curses.py         |  5 +++++
 nyx/panel/__init__.py | 10 ++--------
 nyx/panel/graph.py    |  2 +-
 nyx/panel/log.py      |  2 +-
 nyx/popups.py         |  8 ++++----
 5 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/nyx/curses.py b/nyx/curses.py
index 0b6e24a..97ad02a 100644
--- a/nyx/curses.py
+++ b/nyx/curses.py
@@ -66,6 +66,7 @@ if we want Windows support in the future too.
 from __future__ import absolute_import
 
 import curses
+import threading
 
 import stem.util.conf
 import stem.util.enum
@@ -73,7 +74,11 @@ import stem.util.system
 
 from nyx import msg, log
 
+# Curses screen we've initialized and lock for interacting with it. Curses
+# isn't thread safe and concurrency bugs produce especially sinister glitches.
+
 CURSES_SCREEN = None
+CURSES_LOCK = threading.RLock()
 
 # Text colors and attributes. These are *very* commonly used so including
 # shorter aliases (so they can be referenced as just GREEN or BOLD).
diff --git a/nyx/panel/__init__.py b/nyx/panel/__init__.py
index 0394d55..287d756 100644
--- a/nyx/panel/__init__.py
+++ b/nyx/panel/__init__.py
@@ -7,7 +7,6 @@ import time
 import curses
 import curses.ascii
 import curses.textpad
-from threading import RLock
 
 import nyx.curses
 import stem.util.log
@@ -15,11 +14,6 @@ import stem.util.log
 from nyx.curses import HIGHLIGHT
 from stem.util import conf, str_tools
 
-# global ui lock governing all panel instances (curses isn't thread save and
-# concurrency bugs produce especially sinister glitches)
-
-CURSES_LOCK = RLock()
-
 PASS = -1
 
 __all__ = [
@@ -457,7 +451,7 @@ class Panel(object):
 
     self.max_y, self.max_x = subwin_max_y, subwin_max_x
 
-    if not CURSES_LOCK.acquire(False):
+    if not nyx.curses.CURSES_LOCK.acquire(False):
       return
 
     try:
@@ -466,7 +460,7 @@ class Panel(object):
         self.draw(self.max_x, self.max_y)
       self.win.refresh()
     finally:
-      CURSES_LOCK.release()
+      nyx.curses.CURSES_LOCK.release()
 
   def hline(self, y, x, length, *attributes):
     """
diff --git a/nyx/panel/graph.py b/nyx/panel/graph.py
index 257716e..20a64c0 100644
--- a/nyx/panel/graph.py
+++ b/nyx/panel/graph.py
@@ -475,7 +475,7 @@ class GraphPanel(nyx.panel.Panel):
 
     control = nyx.controller.get_controller()
 
-    with nyx.panel.CURSES_LOCK:
+    with nyx.curses.CURSES_LOCK:
       try:
         while True:
           msg = 'press the down/up to resize the graph, and enter when done'
diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index 92e3f90..3ab53f3 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -239,7 +239,7 @@ class LogPanel(nyx.panel.Panel, threading.Thread):
       if key_press.match('c'):
         self.clear()
     elif key.match('f'):
-      with nyx.panel.CURSES_LOCK:
+      with nyx.curses.CURSES_LOCK:
         initial_selection = 1 if self._filter.selection() else 0
         options = ['None'] + self._filter.latest_selections() + ['New...']
         selection = nyx.popups.show_menu('Log Filter:', options, initial_selection)
diff --git a/nyx/popups.py b/nyx/popups.py
index 61273f3..f29c9c8 100644
--- a/nyx/popups.py
+++ b/nyx/popups.py
@@ -63,13 +63,13 @@ def popup_window(height = -1, width = -1, top = 0, left = 0, below_static = True
       popup.redraw(True)
 
       if popup.win is not None:
-        nyx.panel.CURSES_LOCK.acquire()
+        nyx.curses.CURSES_LOCK.acquire()
         return (popup, popup.max_x - 1, popup.max_y)
       else:
         return (None, 0, 0)
 
     def __exit__(self, exit_type, value, traceback):
-      nyx.panel.CURSES_LOCK.release()
+      nyx.curses.CURSES_LOCK.release()
       nyx.controller.get_controller().redraw(False)
 
   return _Popup()
@@ -85,7 +85,7 @@ def input_prompt(msg, initial_value = ''):
     initial_value - initial value of the field
   """
 
-  with nyx.panel.CURSES_LOCK:
+  with nyx.curses.CURSES_LOCK:
     control = nyx.controller.get_controller()
     msg_panel = control.get_panel('msg')
     msg_panel.set_message(msg)
@@ -107,7 +107,7 @@ def show_msg(msg, max_wait = None, attr = HIGHLIGHT):
     attr    - attributes with which to draw the message
   """
 
-  with nyx.panel.CURSES_LOCK:
+  with nyx.curses.CURSES_LOCK:
     control = nyx.controller.get_controller()
     control.set_msg(msg, attr, True)
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits