+class AbortEvent:
+    """
+    Convenience class that represents a kind of threading.Event that
+    raises AbortedException when called (see the __call__ method, everything
+    else is just to make it look like threading.Event).
+    """
+    
+    def __init__(self):
+        self.__ev = threading.Event()
+
+    def __call__(self, timeout=None):
+        """See if event has been set (wait at most timeout if given).  If so, 
+        raise AbortedException. Otherwise return None. Allows you to do
+        'while not event():' which will always succeed unless the event 
+        has been set (then AbortedException will cause while to exit)."""
+        if timeout:
+            self.__ev.wait(timeout)
+        if self.__ev.isSet():
+            raise AbortedException()
+        return None
+    
+    def __getattr__(self, name):
+        """This allows us to be a kind of threading.Event."""
+        if name in ('set','clear','wait','isSet'):
+            return getattr(self.__ev, name)
+
+