bpo-43234: Prohibit non-ThreadPoolExecutor in loop.set_default_executor (GH-24540)
This commit is contained in:
parent
a1092f6249
commit
ddd5f36971
@ -1132,16 +1132,12 @@ Executing code in thread or process pools
|
|||||||
.. method:: loop.set_default_executor(executor)
|
.. method:: loop.set_default_executor(executor)
|
||||||
|
|
||||||
Set *executor* as 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
|
*executor* must be an instance of
|
||||||
:class:`~concurrent.futures.ThreadPoolExecutor`.
|
:class:`~concurrent.futures.ThreadPoolExecutor`.
|
||||||
|
|
||||||
.. deprecated:: 3.8
|
.. versionchanged:: 3.11
|
||||||
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
|
*executor* must be an instance of
|
||||||
:class:`concurrent.futures.ThreadPoolExecutor`.
|
:class:`~concurrent.futures.ThreadPoolExecutor`.
|
||||||
|
|
||||||
|
|
||||||
Error Handling API
|
Error Handling API
|
||||||
|
@ -188,6 +188,15 @@ This section lists previously described changes and other bugfixes
|
|||||||
that may require changes to your code.
|
that may require changes to your code.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in the Python API
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
* 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`.)
|
||||||
|
|
||||||
|
|
||||||
C API Changes
|
C API Changes
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
@ -814,11 +814,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||||||
|
|
||||||
def set_default_executor(self, executor):
|
def set_default_executor(self, executor):
|
||||||
if not isinstance(executor, concurrent.futures.ThreadPoolExecutor):
|
if not isinstance(executor, concurrent.futures.ThreadPoolExecutor):
|
||||||
warnings.warn(
|
raise TypeError('executor must be ThreadPoolExecutor instance')
|
||||||
'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
|
self._default_executor = executor
|
||||||
|
|
||||||
def _getaddrinfo_debug(self, host, port, family, type, proto, flags):
|
def _getaddrinfo_debug(self, host, port, family, type, proto, flags):
|
||||||
|
@ -224,14 +224,14 @@ class BaseEventLoopTests(test_utils.TestCase):
|
|||||||
self.loop.set_default_executor(executor)
|
self.loop.set_default_executor(executor)
|
||||||
self.assertIs(executor, self.loop._default_executor)
|
self.assertIs(executor, self.loop._default_executor)
|
||||||
|
|
||||||
def test_set_default_executor_deprecation_warnings(self):
|
def test_set_default_executor_error(self):
|
||||||
executor = mock.Mock()
|
executor = mock.Mock()
|
||||||
|
|
||||||
with self.assertWarns(DeprecationWarning):
|
msg = 'executor must be ThreadPoolExecutor instance'
|
||||||
|
with self.assertRaisesRegex(TypeError, msg):
|
||||||
self.loop.set_default_executor(executor)
|
self.loop.set_default_executor(executor)
|
||||||
|
|
||||||
# Avoid cleaning up the executor mock
|
self.assertIsNone(self.loop._default_executor)
|
||||||
self.loop._default_executor = None
|
|
||||||
|
|
||||||
def test_call_soon(self):
|
def test_call_soon(self):
|
||||||
def cb():
|
def cb():
|
||||||
|
@ -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.
|
Loading…
x
Reference in New Issue
Block a user