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

[tor-commits] [stem/master] Python 2.5 doesn't have is_alive() method for Threads



commit 1098d9ad35dc0c04dcced034b1e564706c543c96
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Thu Jun 21 09:31:50 2012 -0700

    Python 2.5 doesn't have is_alive() method for Threads
    
    Though it's not documented [1], the Thread class' isAlive() method was first
    aliased to is_alive() in python 2.6. Also filed a ticket for the documentation
    bug [2].
    
    [1] http://docs.python.org/library/threading.html#threading.Thread.is_alive
    [2] http://bugs.python.org/issue15126
---
 stem/control.py |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 47b08c9..4e6e4f2 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -54,6 +54,12 @@ State = stem.util.enum.Enum("INIT", "RESET", "CLOSED")
 
 UNDEFINED = "<Undefined_ >"
 
+# TODO: The Thread's isAlive() method was changed to the more conventional
+# is_alive() in python 2.6 and above. We should use that when dropping python
+# 2.5 compatability...
+# http://docs.python.org/library/threading.html#threading.Thread.is_alive
+# http://bugs.python.org/issue15126
+
 class BaseController:
   """
   Controller for the tor process. This is a minimal base class for other
@@ -282,7 +288,7 @@ class BaseController:
     # joins on our threads if it's safe to do so
     
     for t in (self._reader_thread, self._event_thread):
-      if t and t.is_alive() and threading.current_thread() != t:
+      if t and t.isAlive() and threading.current_thread() != t:
         t.join()
     
     self._notify_status_listeners(State.CLOSED, False)
@@ -338,12 +344,12 @@ class BaseController:
     # single thread, which would cause an unexpeceted exception. Best be safe.
     
     with self._socket._get_send_lock():
-      if not self._reader_thread or not self._reader_thread.is_alive():
+      if not self._reader_thread or not self._reader_thread.isAlive():
         self._reader_thread = threading.Thread(target = self._reader_loop, name = "Tor Listener")
         self._reader_thread.setDaemon(True)
         self._reader_thread.start()
       
-      if not self._event_thread or not self._event_thread.is_alive():
+      if not self._event_thread or not self._event_thread.isAlive():
         self._event_thread = threading.Thread(target = self._event_loop, name = "Event Notifier")
         self._event_thread.setDaemon(True)
         self._event_thread.start()



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits