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

atagar at torproject.org atagar at torproject.org
Mon Jun 25 01:45:01 UTC 2012


commit 9a8ac67f57fc203eb20dddea3aa09ba49bfe7a97
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Jun 20 10:35:17 2012 -0700

    Python 2.5 doesn't have is_set() method for Events
    
    In python 2.5 the threading module used camel case method names. They also
    accepted the underscore convention (the 'official' style for python) in python
    2.6, but until we drop 2.5 compatability we need to use the camel case
    versions.
---
 stem/descriptor/reader.py |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index 676676f..7a7e565 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -85,6 +85,11 @@ import stem.descriptor
 # flag to indicate when the reader thread is out of descriptor files to read
 FINISHED = "DONE"
 
+# TODO: The threading.Event's isSet() method was changed to the more
+# conventional is_set() in python 2.6 and above. We should use that when
+# dropping python 2.5 compatability...
+# http://docs.python.org/library/threading.html#threading.Event.is_set
+
 class FileSkipped(Exception):
   "Base error when we can't provide descriptor data from a file."
 
@@ -336,7 +341,7 @@ class DescriptorReader:
     new_processed_files = {}
     remaining_files = list(self._targets)
     
-    while remaining_files and not self._is_stopped.is_set():
+    while remaining_files and not self._is_stopped.isSet():
       target = remaining_files.pop(0)
       
       if not os.path.exists(target):
@@ -355,20 +360,20 @@ class DescriptorReader:
             self._handle_file(os.path.join(root, filename), new_processed_files)
           
           # this can take a while if, say, we're including the root directory
-          if self._is_stopped.is_set(): break
+          if self._is_stopped.isSet(): break
       else:
         self._handle_file(target, new_processed_files)
     
     self._processed_files = new_processed_files
     
-    if not self._is_stopped.is_set():
+    if not self._is_stopped.isSet():
       self._unreturned_descriptors.put(FINISHED)
     
     self._iter_notice.set()
   
   def __iter__(self):
     with self._iter_lock:
-      while not self._is_stopped.is_set():
+      while not self._is_stopped.isSet():
         try:
           descriptor = self._unreturned_descriptors.get_nowait()
           
@@ -427,7 +432,7 @@ class DescriptorReader:
     try:
       with open(target) as target_file:
         for desc in stem.descriptor.parse_file(target, target_file):
-          if self._is_stopped.is_set(): return
+          if self._is_stopped.isSet(): return
           self._unreturned_descriptors.put(desc)
           self._iter_notice.set()
     except TypeError, exc:
@@ -445,7 +450,7 @@ class DescriptorReader:
             entry = tar_file.extractfile(tar_entry)
             
             for desc in stem.descriptor.parse_file(target, entry):
-              if self._is_stopped.is_set(): return
+              if self._is_stopped.isSet(): return
               self._unreturned_descriptors.put(desc)
               self._iter_notice.set()
             





More information about the tor-commits mailing list