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

[or-cvs] r17939: {torctl} Fix issues with Connection.close() never actually killing th (torctl/trunk/python/TorCtl)



Author: mikeperry
Date: 2009-01-05 19:11:43 -0500 (Mon, 05 Jan 2009)
New Revision: 17939

Modified:
   torctl/trunk/python/TorCtl/TorCtl.py
Log:

Fix issues with Connection.close() never actually killing the
controlling thread.



Modified: torctl/trunk/python/TorCtl/TorCtl.py
===================================================================
--- torctl/trunk/python/TorCtl/TorCtl.py	2009-01-06 00:04:42 UTC (rev 17938)
+++ torctl/trunk/python/TorCtl/TorCtl.py	2009-01-06 00:11:43 UTC (rev 17939)
@@ -366,6 +366,8 @@
     try:
       self._queue.put("CLOSE")
       self._eventQueue.put((time.time(), "CLOSE"))
+      self._closed = 1
+      self._s.close()
     finally:
       self._sendLock.release()
 
@@ -392,8 +394,11 @@
       try:
         isEvent, reply = self._read_reply()
       except:
-        self._err(sys.exc_info())
-        return
+        if not self._closed:
+          self._err(sys.exc_info())
+          return
+        else:
+		  isEvent = 0
 
       if isEvent:
         if self._handler is not None:
@@ -401,9 +406,8 @@
       else:
         cb = self._queue.get() # atomic..
         if cb == "CLOSE":
-          self._s.close()
           self._s = None
-          self._closed = 1
+          plog("INFO", "Closed control connection. Exiting thread.")
           return
         else:
           cb(reply)
@@ -442,6 +446,7 @@
         plog("DEBUG", "Ignoring incompatible syntactic sugar: 650 OK")
         continue
       if reply == "CLOSE":
+        plog("INFO", "Event loop recieved close message.")
         return
       try:
         self._handleFn(timestamp, reply)