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

[minion-cvs] Handle incompatibilities with python 2.4



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv26438/lib/mixminion

Modified Files:
	Common.py Packet.py ThreadUtils.py 
Log Message:
Handle incompatibilities with python 2.4

Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.143
retrieving revision 1.144
diff -u -d -r1.143 -r1.144
--- Common.py	2 Dec 2004 23:39:01 -0000	1.143
+++ Common.py	7 Feb 2005 06:18:40 -0000	1.144
@@ -1270,7 +1270,7 @@
 
     def __float__(self):
         """Return the number of seconds in this duration"""
-        return self.seconds
+        return float(self.seconds)
 
     def __int__(self):
         """Return the number of seconds in this duration"""

Index: Packet.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Packet.py,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- Packet.py	27 Jul 2004 03:23:23 -0000	1.79
+++ Packet.py	7 Feb 2005 06:18:40 -0000	1.80
@@ -1013,7 +1013,7 @@
     _ZLIB_LIBRARY_OK = 0.5
     if ver in ("1.1.2", "1.1.3", "1.1.4", "1.2.0", "1.2.0.1", "1.2.0.2",
                "1.2.0.3", "1.2.0.4", "1.2.0.5", "1.2.0.6", "1.2.0.7",
-               "1.2.0.8", "1.2.1", "1.2.1.1"):
+               "1.2.0.8", "1.2.1", "1.2.1.1", "1.2.1.2"):
         _ZLIB_LIBRARY_OK = 1
         return
 

Index: ThreadUtils.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ThreadUtils.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- ThreadUtils.py	27 Dec 2004 00:15:57 -0000	1.9
+++ ThreadUtils.py	7 Feb 2005 06:18:40 -0000	1.10
@@ -30,26 +30,55 @@
 del Queue
 del Empty
 
-class ClearableQueue(MessageQueue):
-    """Extended version of python's Queue class that supports removing
-       all the items from the queue."""
-    def clear(self):
-        """Remove all the items from this queue."""
-        # If the queue is empty, return.
-        if not self.esema.acquire(0):
-            return
-        self.mutex.acquire()
-        was_full = self._full()
-        self._clear()
-        assert self._empty()
-        # If the queue used to be full, it isn't anymore.
-        if was_full:
-            self.fsema.release()
-        self.mutex.release()
+try:
+    q = MessageQueue()
+    q.not_full
+except:
+    BUILTIN_QUEUE_USES_CONDITIONS = 0
+else:
+    BUILTIN_QUEUE_USES_CONDITIONS = 1
+del q
+
+if BUILTIN_QUEUE_USES_CONDITIONS:
+    class ClearableQueue(MessageQueue):
+        """Extended version of python's Queue class that supports removing
+           all the items from the queue."""
+        def clear(self):
+            """Remove all the items from this queue."""
+            # If the queue is empty, return.
+            self.not_empty.acquire()
+            try:
+                if self._empty(): return
+                self._clear()
+                self.not_full.notify()
+            finally:
+                self.not_empty.release()
+
+        def _clear(self):
+            """Backend for _clear"""
+            self.queue.clear()
+else:
+    class ClearableQueue(MessageQueue):
+        """Extended version of python's Queue class that supports removing
+           all the items from the queue."""
+        def clear(self):
+            """Remove all the items from this queue."""
+            # If the queue is empty, return.
+            if not self.esema.acquire(0):
+                return
+            self.mutex.acquire()
+            was_full = self._full()
+            self._clear()
+            assert self._empty()
+            # If the queue used to be full, it isn't anymore.
+            if was_full:
+                self.fsema.release()
+            self.mutex.release()
+
+        def _clear(self):
+            """Backend for _clear"""
+            del self.queue[:]
 
-    def _clear(self):
-        """Backend for _clear"""
-        del self.queue[:]
 
 try:
     q = MessageQueue()