summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrian.quinlan <devnull@localhost>2009-05-28 11:10:35 +0000
committerbrian.quinlan <devnull@localhost>2009-05-28 11:10:35 +0000
commitb4849a1e72600c2d45eae9bb3fcf764feba48d9f (patch)
tree3363c5504e0ef793b4d3c4f7b98f81a1c97ba831
parentefc958fb0e68add5a512a633aea88276e91f5eab (diff)
downloadfutures-b4849a1e72600c2d45eae9bb3fcf764feba48d9f.tar.gz
Python 2.4 compatibility
-rw-r--r--python2/futures/_base.py24
-rw-r--r--python2/futures/process.py2
-rw-r--r--python2/futures/thread.py2
3 files changed, 25 insertions, 3 deletions
diff --git a/python2/futures/_base.py b/python2/futures/_base.py
index 95c4004..5ad4229 100644
--- a/python2/futures/_base.py
+++ b/python2/futures/_base.py
@@ -3,6 +3,25 @@ import logging
import threading
import time
+# The "any" and "all" builtins weren't introduced until Python 2.5.
+try:
+ any
+except NameError:
+ def any(iterable):
+ for element in iterable:
+ if element:
+ return True
+ return False
+
+try:
+ all
+except NameError:
+ def all(iterable):
+ for element in iterable:
+ if not element:
+ return False
+ return True
+
FIRST_COMPLETED = 0
FIRST_EXCEPTION = 1
ALL_COMPLETED = 2
@@ -481,11 +500,14 @@ class Executor(object):
yield future.result()
else:
yield future.result(end_time - time.time())
- finally:
+ except:
+ # Python 2.4 and earlier didn't allow yield statements in
+ # try/finally blocks
try:
fs.cancel(timeout=0)
except TimeoutError:
pass
+ raise
def map(self, func, *iterables, **kwargs):
"""Returns a iterator equivalent to map(fn, iter).
diff --git a/python2/futures/process.py b/python2/futures/process.py
index 044a80a..3e16e80 100644
--- a/python2/futures/process.py
+++ b/python2/futures/process.py
@@ -37,7 +37,7 @@ def _process_worker(call_queue, result_queue, shutdown):
else:
try:
r = call_item.call()
- except BaseException, e:
+ except Exception, e:
result_queue.put(_ResultItem(call_item.work_id,
exception=e))
else:
diff --git a/python2/futures/thread.py b/python2/futures/thread.py
index 0ffe798..5834fd4 100644
--- a/python2/futures/thread.py
+++ b/python2/futures/thread.py
@@ -38,7 +38,7 @@ class _WorkItem(object):
try:
result = self.call()
- except BaseException, e:
+ except Exception, e:
set_future_exception(self.future, self.completion_tracker, e)
else:
set_future_result(self.future, self.completion_tracker, result)