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

[or-cvs] r20504: {torctl} Try to be better about dying if TorCtl is horked. (torctl/branches/stable/python/TorCtl)



Author: mikeperry
Date: 2009-09-08 16:50:55 -0400 (Tue, 08 Sep 2009)
New Revision: 20504

Modified:
   torctl/branches/stable/python/TorCtl/PathSupport.py
   torctl/branches/stable/python/TorCtl/TorCtl.py
Log:

Try to be better about dying if TorCtl is horked.



Modified: torctl/branches/stable/python/TorCtl/PathSupport.py
===================================================================
--- torctl/branches/stable/python/TorCtl/PathSupport.py	2009-09-08 19:33:43 UTC (rev 20503)
+++ torctl/branches/stable/python/TorCtl/PathSupport.py	2009-09-08 20:50:55 UTC (rev 20504)
@@ -1314,12 +1314,14 @@
     Schedules an immediate job to be run before the next event is
     processed.
     """
+    assert(self.c.is_live())
     self.imm_jobs.put(job)
 
   def schedule_low_prio(self, job):
     """
     Schedules a job to be run when a non-time critical event arrives.
     """
+    assert(self.c.is_live())
     self.low_prio_jobs.put(job)
 
   def reset(self):
@@ -1350,6 +1352,7 @@
     processed. Also notifies the selection manager that it needs
     to update itself.
     """
+    assert(self.c.is_live())
     def notlambda(this):
       job(this.selmgr)
       this.do_reconfigure = True

Modified: torctl/branches/stable/python/TorCtl/TorCtl.py
===================================================================
--- torctl/branches/stable/python/TorCtl/TorCtl.py	2009-09-08 19:33:43 UTC (rev 20503)
+++ torctl/branches/stable/python/TorCtl/TorCtl.py	2009-09-08 20:50:55 UTC (rev 20504)
@@ -439,15 +439,20 @@
     finally:
       self._sendLock.release()
 
+  def is_live(self):
+    """ Returns true iff the connection is alive and healthy"""
+    return self._thread.isAlive() and self._eventThread.isAlive() and not \
+           self._closed
+
   def launch_thread(self, daemon=1):
     """Launch a background thread to handle messages from the Tor process."""
     assert self._thread is None
-    t = threading.Thread(target=self._loop)
+    t = threading.Thread(target=self._loop, name="TorLoop")
     if daemon:
       t.setDaemon(daemon)
     t.start()
     self._thread = t
-    t = threading.Thread(target=self._eventLoop)
+    t = threading.Thread(target=self._eventLoop, name="EventLoop")
     if daemon:
       t.setDaemon(daemon)
     t.start()