diff -r a8e74448678c Lib/asyncio/futures.py --- a/Lib/asyncio/futures.py Tue Aug 09 15:07:06 2016 +0100 +++ b/Lib/asyncio/futures.py Fri Aug 12 14:24:45 2016 +0900 @@ -110,49 +110,7 @@ self.loop.call_exception_handler({'message': msg}) -class Future: - """This class is *almost* compatible with concurrent.futures.Future. - - Differences: - - - result() and exception() do not take a timeout argument and - raise an exception when the future isn't done yet. - - - Callbacks registered with add_done_callback() are always called - via the event loop's call_soon_threadsafe(). - - - This class is not compatible with the wait() and as_completed() - methods in the concurrent.futures package. - - (In Python 3.4 or later we may be able to unify the implementations.) - """ - - # Class variables serving as defaults for instance variables. - _state = _PENDING - _result = None - _exception = None - _loop = None - _source_traceback = None - - _blocking = False # proper use of future (yield vs yield from) - - _log_traceback = False # Used for Python 3.4 and later - _tb_logger = None # Used for Python 3.3 only - - def __init__(self, *, loop=None): - """Initialize the future. - - The optional event_loop argument allows explicitly setting the event - loop object used by the future. If it's not provided, the future uses - the default event loop. - """ - if loop is None: - self._loop = events.get_event_loop() - else: - self._loop = loop - self._callbacks = [] - if self._loop.get_debug(): - self._source_traceback = traceback.extract_stack(sys._getframe(1)) +class _BaseFuture: def __format_callbacks(self): cb = self._callbacks @@ -214,6 +172,51 @@ context['source_traceback'] = self._source_traceback self._loop.call_exception_handler(context) + +class Future(_BaseFuture): + """This class is *almost* compatible with concurrent.futures.Future. + + Differences: + + - result() and exception() do not take a timeout argument and + raise an exception when the future isn't done yet. + + - Callbacks registered with add_done_callback() are always called + via the event loop's call_soon_threadsafe(). + + - This class is not compatible with the wait() and as_completed() + methods in the concurrent.futures package. + + (In Python 3.4 or later we may be able to unify the implementations.) + """ + + # Class variables serving as defaults for instance variables. + _state = _PENDING + _result = None + _exception = None + _loop = None + _source_traceback = None + + _blocking = False # proper use of future (yield vs yield from) + + _log_traceback = False # Used for Python 3.4 and later + _tb_logger = None # Used for Python 3.3 only + + def __init__(self, *, loop=None): + """Initialize the future. + + The optional event_loop argument allows to explicitly set the event + loop object used by the future. If it's not provided, the future uses + the default event loop. + """ + if loop is None: + self._loop = events.get_event_loop() + else: + self._loop = loop + self._callbacks = [] + if self._loop.get_debug(): + self._source_traceback = traceback.extract_stack(sys._getframe(1)) + def cancel(self): """Cancel the future and schedule callbacks. @@ -408,6 +411,21 @@ dest.set_result(result) +try: + import _futures +except ImportError: + pass +else: + class Future(_BaseFuture, _futures.Future): + pass + + _futures._init_module( + traceback.extract_stack, + events.get_event_loop, + InvalidStateError, + CancelledError) + + def _chain_future(source, destination): """Chain two futures so that when one completes, so does the other. diff -r a8e74448678c Modules/Setup.dist --- a/Modules/Setup.dist Tue Aug 09 15:07:06 2016 +0100 +++ b/Modules/Setup.dist Fri Aug 12 14:24:45 2016 +0900 @@ -180,6 +180,7 @@ #_datetime _datetimemodule.c # datetime accelerator #_bisect _bisectmodule.c # Bisection algorithms #_heapq _heapqmodule.c # Heap queue algorithm +#_futures _futuresmodule.c # Fast asyncio Future #unicodedata unicodedata.c # static Unicode character database diff -r a8e74448678c PCbuild/pythoncore.vcxproj --- a/PCbuild/pythoncore.vcxproj Tue Aug 09 15:07:06 2016 +0100 +++ b/PCbuild/pythoncore.vcxproj Fri Aug 12 14:24:45 2016 +0900 @@ -218,6 +218,7 @@ + diff -r a8e74448678c PCbuild/pythoncore.vcxproj.filters --- a/PCbuild/pythoncore.vcxproj.filters Tue Aug 09 15:07:06 2016 +0100 +++ b/PCbuild/pythoncore.vcxproj.filters Fri Aug 12 14:24:45 2016 +0900 @@ -461,6 +461,9 @@ Modules + + Modules + Modules diff -r a8e74448678c setup.py --- a/setup.py Tue Aug 09 15:07:06 2016 +0100 +++ b/setup.py Fri Aug 12 14:24:45 2016 +0900 @@ -655,6 +655,8 @@ exts.append( Extension('unicodedata', ['unicodedata.c']) ) # _opcode module exts.append( Extension('_opcode', ['_opcode.c']) ) + # Fast asyncio Future implementation + exts.append( Extension("_futures", ["_futuresmodule.c"]) ) # Modules with some UNIX dependencies -- on by default: # (If you have a really backward UNIX, select and socket may not be