Author: gsim
Date: Thu Jul 26 09:08:40 2007
New Revision: 559869

URL: http://svn.apache.org/viewvc?view=rev&rev=559869
Log:
Changed use of Event to directly use Condition to workaround problems on other 
platforms (where Event.wait() returned immediately after a set()/clear()).


Modified:
    incubator/qpid/trunk/qpid/python/qpid/peer.py

Modified: incubator/qpid/trunk/qpid/python/qpid/peer.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/peer.py?view=diff&rev=559869&r1=559868&r2=559869
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/peer.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/peer.py Thu Jul 26 09:08:40 2007
@@ -351,8 +351,8 @@
 
 class ExecutionCompletion:
   def __init__(self):
-    self.completed = threading.Event()
-    self.sequence = Sequence(0)
+    self.condition = threading.Condition()
+    self.sequence = Sequence(1)
     self.command_id = 0
     self.mark = 0
 
@@ -362,19 +362,27 @@
       self.command_id = self.sequence.next()
 
   def close(self):
-    self.completed.set()    
+    self.condition.acquire()
+    try:
+      self.condition.notifyAll()
+    finally:
+      self.condition.release()
 
   def complete(self, mark):
-    self.mark = mark
-    self.completed.set()    
-    self.completed.clear()    
+    self.condition.acquire()
+    try:
+      self.mark = mark
+      self.condition.notifyAll()
+    finally:
+      self.condition.release()
 
   def wait(self, point_of_interest=-1, timeout=None):
-    """
-    todo: really want to allow different threads to call this with
-    different points of interest on the same channel, this is a quick
-    hack for now
-    """
     if point_of_interest == -1: point_of_interest = self.command_id
-    self.completed.wait(timeout)
+    self.condition.acquire()
+    try:
+      if point_of_interest > self.mark:
+        self.condition.wait(timeout)
+    finally:
+      self.condition.release()
+    #todo: retry until timed out or closed 
     return point_of_interest <= self.mark


Reply via email to