.. method:: AbstractEventLoop.set_default_executor(executor)
- Set the default executor used by :meth:`run_in_executor`.
+ Set *executor* as the default executor used by :meth:`run_in_executor`.
+ *executor* should 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.
Error Handling API
They will be removed in Python 3.9.
(Contributed by Serhiy Storchaka in :issue:`29209`.)
+* Passing an object that is not an instance of
+ :class:`concurrent.futures.ThreadPoolExecutor` to
+ :meth:`asyncio.AbstractEventLoop.set_default_executor()` is
+ deprecated and will be prohibited in Python 3.9.
+ (Contributed by Elvis Pranskevichus in :issue:`34075`.)
+
Removed
=======
executor.submit(func, *args), loop=self)
def set_default_executor(self, executor):
+ if not isinstance(executor, concurrent.futures.ThreadPoolExecutor):
+ warnings.warn(
+ 'Using the default executor that is not an instance of '
+ 'ThreadPoolExecutor is deprecated and will be prohibited '
+ 'in Python 3.9',
+ DeprecationWarning, 2)
self._default_executor = executor
def _getaddrinfo_debug(self, host, port, family, type, proto, flags):
"""Tests for base_events.py"""
+import concurrent.futures
import errno
import logging
import math
self.assertFalse(self.loop._ready)
def test_set_default_executor(self):
- executor = mock.Mock()
+ class DummyExecutor(concurrent.futures.ThreadPoolExecutor):
+ def submit(self, fn, *args, **kwargs):
+ raise NotImplementedError(
+ 'cannot submit into a dummy executor')
+
+ executor = DummyExecutor()
self.loop.set_default_executor(executor)
self.assertIs(executor, self.loop._default_executor)
+ def test_set_default_executor_deprecation_warnings(self):
+ executor = mock.Mock()
+
+ with self.assertWarns(DeprecationWarning):
+ self.loop.set_default_executor(executor)
+
def test_call_soon(self):
def cb():
pass
--- /dev/null
+Deprecate passing non-ThreadPoolExecutor instances to
+:meth:`AbstractEventLoop.set_default_executor`.