diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-01-04 01:42:53 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-01-04 01:42:53 +0100 |
commit | 8c7d4cfeffdeaa94ca2890ea14680365036d81b9 (patch) | |
tree | c57df50e05f30a1a94e4b73415b7b761027fa9d3 | |
parent | de47cee545996b8e939a49c8363aa2cb572176fe (diff) | |
download | trollius-8c7d4cfeffdeaa94ca2890ea14680365036d81b9.tar.gz |
Use concurrent.futures classes and constants when the module is available
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | asyncio/futures.py | 29 | ||||
-rw-r--r-- | asyncio/tasks.py | 13 |
3 files changed, 28 insertions, 15 deletions
@@ -5,7 +5,6 @@ - test_queues.py - test_tasks.py -* Use backport of concurrent.futures * unix_events, RuntimeError on signal.signal: test_unix_events.SelectorEventLoopTests.test_add_signal_handler_install_error * Fix all FIXME in the code diff --git a/asyncio/futures.py b/asyncio/futures.py index 27a0feb..28f7866 100644 --- a/asyncio/futures.py +++ b/asyncio/futures.py @@ -24,17 +24,24 @@ _FINISHED = 'FINISHED' _PY34 = sys.version_info >= (3, 4) -class Error(Exception): - """Base class for all future-related exceptions.""" - pass - -class CancelledError(Error): - """The Future was cancelled.""" - pass - -class TimeoutError(Error): - """The operation exceeded the given deadline.""" - pass +try: + import concurrent.futures._base +except ImportError: + class Error(Exception): + """Base class for all future-related exceptions.""" + pass + + class CancelledError(Error): + """The Future was cancelled.""" + pass + + class TimeoutError(Error): + """The operation exceeded the given deadline.""" + pass +else: + Error = concurrent.futures._base.Error + CancelledError = concurrent.futures.CancelledError + TimeoutError = concurrent.futures.TimeoutError STACK_DEBUG = logging.DEBUG - 1 # heavy-duty debugging diff --git a/asyncio/tasks.py b/asyncio/tasks.py index 596b71f..46a9346 100644 --- a/asyncio/tasks.py +++ b/asyncio/tasks.py @@ -269,9 +269,16 @@ class Task(futures.Future): # wait() and as_completed() similar to those in PEP 3148. -FIRST_COMPLETED = 'FIRST_COMPLETED' -FIRST_EXCEPTION = 'FIRST_EXCEPTION' -ALL_COMPLETED = 'ALL_COMPLETED' +try: + import concurrent.futures +except ImportError: + FIRST_COMPLETED = 'FIRST_COMPLETED' + FIRST_EXCEPTION = 'FIRST_EXCEPTION' + ALL_COMPLETED = 'ALL_COMPLETED' +else: + FIRST_COMPLETED = concurrent.futures.FIRST_COMPLETED + FIRST_EXCEPTION = concurrent.futures.FIRST_EXCEPTION + ALL_COMPLETED = concurrent.futures.ALL_COMPLETED @coroutine |