8000 bpo-43234: Prohibit non-ThreadPoolExecutor in loop.set_default_executor by illia-v · Pull Request #24540 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-43234: Prohibit non-ThreadPoolExecutor in loop.set_default_executor #24540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-43234: Prohibit non-ThreadPoolExecutor in loop.set_default_executor
  • Loading branch information
illia-v committed Feb 15, 2021
commit ab33a36a23463d126739ff177520020b29416dc5
12 changes: 4 additions & 8 deletions Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1127,16 +1127,12 @@ Executing code in thread or process pools
.. method:: loop.set_default_executor(executor)

Set *executor* as the default executor used by :meth:`run_in_executor`.
*executor* should be an instance of
*executor* must be an instance of
:class:`~concurrent.futures.ThreadPoolExecutor`.

.. deprecated:: 3.8
Using an executor that is not an instance of
:class:`~concurrent.futures.ThreadPoolExecutor` is deprecated and
will trigger an error in Python 3.9.

*executor* must be an instance of
:class:`concurrent.futures.ThreadPoolExecutor`.
.. deprecated-removed:: 3.8 3.10
Accepting an ``executor`` that is not an instance of
:class:`~concurrent.futures.ThreadPoolExecutor`.


Error Handling API
Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,10 @@ Removed
(Contributed by Yurii Karabas, Andrew Svetlov, Yury Selivanov and Kyle Stanley
in :issue:`42392`.)

* Prohibited passing non-:class:`concurrent.futures.ThreadPoolExecutor`
executors to :meth:`loop.set_default_executor` following a deprecation in
Python 3.8.
(Contributed by Illia Volochii in :issue:`43234`.)

Porting to Python 3.10
======================
Expand Down
6 changes: 2 additions & 4 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,11 +814,9 @@ def run_in_executor(self, executor, func, *args):

def set_default_executor(self, executor):
if not isinstance(executor, concurrent.futures.ThreadPoolExecutor):
warnings.warn(
raise RuntimeError(
'Using the default executor that is not an instance of '
'ThreadPoolExecutor is deprecated and will be prohibited '
'in Python 3.9',
DeprecationWarning, 2)
'ThreadPoolExecutor is prohibited')
self._default_executor = executor

def _getaddrinfo_debug(self, host, port, family, type, proto, flags):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_asyncio/test_base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def submit(self, fn, *args, **kwargs):
def test_set_default_executor_deprecation_warnings(self):
executor = mock.Mock()

with self.assertWarns(DeprecationWarning):
with self.assertRaises(RuntimeError):
self.loop.set_default_executor(executor)

# Avoid cleaning up the executor mock
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Prohibit passing non-:class:`concurrent.futures.ThreadPoolExecutor`
executors to :meth:`loop.set_default_executor` following a deprecation in
Python 3.8. Patch by Illia Volochii.
0