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

[or-cvs] r22378: {torctl} Alter launch_thread() to return the EventHandler thread, as (torctl/trunk/python/TorCtl)



Author: mikeperry
Date: 2010-05-22 23:07:09 +0000 (Sat, 22 May 2010)
New Revision: 22378

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

Alter launch_thread() to return the EventHandler thread, as
this provides a more reliable indication as to when we are
done processing events on the connection.

For some reason python's socket.close() does not cause a
concurrent blocking readline() to return immediately.. This
prevents the 'TorThread' (the _loop() thread) from
terminating until more data arrives.



Modified: torctl/trunk/python/TorCtl/TorCtl.py
===================================================================
--- torctl/trunk/python/TorCtl/TorCtl.py	2010-05-22 22:09:13 UTC (rev 22377)
+++ torctl/trunk/python/TorCtl/TorCtl.py	2010-05-22 23:07:09 UTC (rev 22378)
@@ -460,6 +460,10 @@
       self._queue.put("CLOSE")
       self._eventQueue.put((time.time(), "CLOSE"))
       self._closed = 1
+      # XXX: For some reason, this does not cause the readline in
+      # self._read_reply() to return immediately. The _loop() thread
+      # thus tends to stick around until some event causes data to come
+      # back...
       self._s.close()
       self._eventThread.join()
     finally:
@@ -483,7 +487,9 @@
       t.setDaemon(daemon)
     t.start()
     self._eventThread = t
-    return self._thread
+    # eventThread provides a more reliable indication of when we are done.
+    # The _loop thread won't always die when self.close() is called.
+    return self._eventThread
 
   def _loop(self):
     """Main subthread loop: Read commands from Tor, and handle them either