[or-cvs] Add a callback to get exceptions from handler thread.

Nick Mathewson nickm at seul.org
Thu Nov 17 18:30:36 UTC 2005


Update of /home/or/cvsroot/control/python
In directory moria:/tmp/cvs-serv30103

Modified Files:
	TorCtl1.py 
Log Message:
Add a callback to get exceptions from handler thread.

Index: TorCtl1.py
===================================================================
RCS file: /home/or/cvsroot/control/python/TorCtl1.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- TorCtl1.py	17 Nov 2005 17:39:56 -0000	1.17
+++ TorCtl1.py	17 Nov 2005 18:30:34 -0000	1.18
@@ -123,6 +123,7 @@
         self._thread = None
         self._closedEx = None
         self._closed = 0
+        self._closeHandler = None
 
     def debug(self, f):
         """DOCDOC"""
@@ -133,6 +134,14 @@
         """
         self._handler = handler
 
+    def set_close_handler(self, handler):
+        """Call 'handler' when the Tor process has closed its connection or
+           given us an exception.  If we close normally, no arguments are
+           provided; otherwise, it will be called with an exception as its
+           argument.
+        """
+        self._closeHandler = handler
+
     def launch_thread(self, daemon=1):
         """Launch a background thread to handle messages from the Tor process."""
         assert self._thread is None
@@ -159,7 +168,6 @@
         """
         while 1:
             ex = None
-            print "."
             try:
                 lines = _read_reply(self._s,self._debugFile)
             except:
@@ -179,6 +187,8 @@
                             cb("EXCEPTION")
                     except Queue.Empty:
                         return
+                if self._closeHandler is not None:
+                    self._closeHandler(ex)
 
             assert lines
             if lines[0][0][0] == "6":



More information about the tor-commits mailing list