Skip to content

Commit ddd5f36

Browse files
authored
bpo-43234: Prohibit non-ThreadPoolExecutor in loop.set_default_executor (GH-24540)
1 parent a1092f6 commit ddd5f36

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

Doc/library/asyncio-eventloop.rst

+4-8
Original file line numberDiff line numberDiff line change
@@ -1132,16 +1132,12 @@ Executing code in thread or process pools
11321132
.. method:: loop.set_default_executor(executor)
11331133

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

1138-
.. deprecated:: 3.8
1139-
Using an executor that is not an instance of
1140-
:class:`~concurrent.futures.ThreadPoolExecutor` is deprecated and
1141-
will trigger an error in Python 3.9.
1142-
1143-
*executor* must be an instance of
1144-
:class:`concurrent.futures.ThreadPoolExecutor`.
1138+
.. versionchanged:: 3.11
1139+
*executor* must be an instance of
1140+
:class:`~concurrent.futures.ThreadPoolExecutor`.
11451141

11461142

11471143
Error Handling API

Doc/whatsnew/3.11.rst

+9
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ This section lists previously described changes and other bugfixes
188188
that may require changes to your code.
189189

190190

191+
Changes in the Python API
192+
-------------------------
193+
194+
* Prohibited passing non-:class:`concurrent.futures.ThreadPoolExecutor`
195+
executors to :meth:`loop.set_default_executor` following a deprecation in
196+
Python 3.8.
197+
(Contributed by Illia Volochii in :issue:`43234`.)
198+
199+
191200
C API Changes
192201
=============
193202

Lib/asyncio/base_events.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -814,11 +814,7 @@ def run_in_executor(self, executor, func, *args):
814814

815815
def set_default_executor(self, executor):
816816
if not isinstance(executor, concurrent.futures.ThreadPoolExecutor):
817-
warnings.warn(
818-
'Using the default executor that is not an instance of '
819-
'ThreadPoolExecutor is deprecated and will be prohibited '
820-
'in Python 3.9',
821-
DeprecationWarning, 2)
817+
raise TypeError('executor must be ThreadPoolExecutor instance')
822818
self._default_executor = executor
823819

824820
def _getaddrinfo_debug(self, host, port, family, type, proto, flags):

Lib/test/test_asyncio/test_base_events.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,14 @@ def submit(self, fn, *args, **kwargs):
224224
self.loop.set_default_executor(executor)
225225
self.assertIs(executor, self.loop._default_executor)
226226

227-
def test_set_default_executor_deprecation_warnings(self):
227+
def test_set_default_executor_error(self):
228228
executor = mock.Mock()
229229

230-
with self.assertWarns(DeprecationWarning):
230+
msg = 'executor must be ThreadPoolExecutor instance'
231+
with self.assertRaisesRegex(TypeError, msg):
231232
self.loop.set_default_executor(executor)
232233

233-
# Avoid cleaning up the executor mock
234-
self.loop._default_executor = None
234+
self.assertIsNone(self.loop._default_executor)
235235

236236
def test_call_soon(self):
237237
def cb():
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Prohibit passing non-:class:`concurrent.futures.ThreadPoolExecutor`
2+
executors to :meth:`loop.set_default_executor` following a deprecation in
3+
Python 3.8. Patch by Illia Volochii.

0 commit comments

Comments
 (0)