bpo-33238: Add InvalidStateError to concurrent.futures. (GH-7056)

Future.set_result and Future.set_exception now raise InvalidStateError
if the futures are not pending or running. This mirrors the behavior
of asyncio.Future, and prevents AssertionErrors in asyncio.wrap_future
when set_result is called multiple times.
This commit is contained in:
jhaydaman 2018-05-30 02:15:06 -05:00 committed by Andrew Svetlov
parent bb9474f1fb
commit 0a28c0d12e
6 changed files with 59 additions and 6 deletions

View file

@ -380,6 +380,11 @@ The :class:`Future` class encapsulates the asynchronous execution of a callable.
This method should only be used by :class:`Executor` implementations and
unit tests.
.. versionchanged:: 3.8
This method raises
:exc:`concurrent.futures.InvalidStateError` if the :class:`Future` is
already done.
.. method:: set_exception(exception)
Sets the result of the work associated with the :class:`Future` to the
@ -388,6 +393,10 @@ The :class:`Future` class encapsulates the asynchronous execution of a callable.
This method should only be used by :class:`Executor` implementations and
unit tests.
.. versionchanged:: 3.8
This method raises
:exc:`concurrent.futures.InvalidStateError` if the :class:`Future` is
already done.
Module Functions
----------------
@ -466,6 +475,13 @@ Exception classes
.. versionadded:: 3.7
.. exception:: InvalidStateError
Raised when an operation is performed on a future that is not allowed
in the current state.
.. versionadded:: 3.8
.. currentmodule:: concurrent.futures.thread
.. exception:: BrokenThreadPool