mailr14083 - /branches/gui_testing/gui/controller.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on August 03, 2011 - 11:17:
Author: bugman
Date: Wed Aug  3 11:17:22 2011
New Revision: 14083

URL: http://svn.gna.org/viewcvs/relax?rev=14083&view=rev
Log:
Created a FIFO object for the relax controller log.

This allows for asynchronous writing to sys.stdout and sending this output to 
the log controller,
preventing the GUI from slowing down calculations by having to wait for the 
GUI to update.


Modified:
    branches/gui_testing/gui/controller.py

Modified: branches/gui_testing/gui/controller.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/controller.py?rev=14083&r1=14082&r2=14083&view=diff
==============================================================================
--- branches/gui_testing/gui/controller.py (original)
+++ branches/gui_testing/gui/controller.py Wed Aug  3 11:17:22 2011
@@ -25,7 +25,9 @@
 """Log window of relax GUI controlling all calculations."""
 
 # Python module imports.
+from Queue import Queue
 import sys
+from thread import start_new_thread
 import wx
 import wx.stc
 
@@ -93,7 +95,7 @@
         if not status.debug and not status.test_mode:
             redir = Redirect_text(self.log_panel)
             sys.stdout = redir
-            sys.stderr = redir
+            #sys.stderr = redir
 
         # Initial update of the controller.
         self.update_controller()
@@ -602,6 +604,15 @@
         # Store the args.
         self.control = control
 
+        # Flag for forcing the killing of the thread.
+        self.active = True
+
+        # Create a FIFO queue.
+        self.queue = Queue()
+
+        # Run the writer thread.
+        start_new_thread(self.writer_thread, ())
+
 
     def write(self, string):
         """Simulate the file object write method.
@@ -610,5 +621,17 @@
         @type string:   str
         """
 
-        # Append the text to the controller asynchronously, with limited 
scroll back.
-        wx.CallAfter(self.control.write, string)
+        # Add the text to the queue, with a flag specifying stdout vs. 
stderr.
+        self.queue.put([string, 0])
+
+
+    def writer_thread(self):
+        """Method run in a thread to read the FIFO and send text to the 
controller."""
+
+        # Inifinite loop.
+        while self.active:
+            # Read from the FIFO (blocking as needed).
+            data = self.queue.get()
+
+            # Append the text to the controller asynchronously, with limited 
scroll back.
+            wx.CallAfter(self.control.write, data[0])




Related Messages


Powered by MHonArc, Updated Wed Aug 03 12:20:01 2011