mirror of
https://github.com/python/cpython.git
synced 2025-09-20 15:40:32 +00:00
Issue #28371: Deprecate passing asyncio.Handles to run_in_executor.
This commit is contained in:
parent
3e56ff0d08
commit
0de3de6cbf
3 changed files with 11 additions and 3 deletions
|
@ -605,6 +605,9 @@ class BaseEventLoop(events.AbstractEventLoop):
|
||||||
if isinstance(func, events.Handle):
|
if isinstance(func, events.Handle):
|
||||||
assert not args
|
assert not args
|
||||||
assert not isinstance(func, events.TimerHandle)
|
assert not isinstance(func, events.TimerHandle)
|
||||||
|
warnings.warn(
|
||||||
|
"Passing Handle to loop.run_in_executor() is deprecated",
|
||||||
|
DeprecationWarning)
|
||||||
if func._cancelled:
|
if func._cancelled:
|
||||||
f = self.create_future()
|
f = self.create_future()
|
||||||
f.set_result(None)
|
f.set_result(None)
|
||||||
|
|
|
@ -358,6 +358,7 @@ class BaseEventLoopTests(test_utils.TestCase):
|
||||||
h = asyncio.Handle(cb, (), self.loop)
|
h = asyncio.Handle(cb, (), self.loop)
|
||||||
h.cancel()
|
h.cancel()
|
||||||
|
|
||||||
|
with self.assertWarnsRegex(DeprecationWarning, "Passing Handle"):
|
||||||
f = self.loop.run_in_executor(None, h)
|
f = self.loop.run_in_executor(None, h)
|
||||||
self.assertIsInstance(f, asyncio.Future)
|
self.assertIsInstance(f, asyncio.Future)
|
||||||
self.assertTrue(f.done())
|
self.assertTrue(f.done())
|
||||||
|
@ -373,11 +374,13 @@ class BaseEventLoopTests(test_utils.TestCase):
|
||||||
|
|
||||||
self.loop.set_default_executor(executor)
|
self.loop.set_default_executor(executor)
|
||||||
|
|
||||||
|
with self.assertWarnsRegex(DeprecationWarning, "Passing Handle"):
|
||||||
res = self.loop.run_in_executor(None, h)
|
res = self.loop.run_in_executor(None, h)
|
||||||
self.assertIs(f, res)
|
self.assertIs(f, res)
|
||||||
|
|
||||||
executor = mock.Mock()
|
executor = mock.Mock()
|
||||||
executor.submit.return_value = f
|
executor.submit.return_value = f
|
||||||
|
with self.assertWarnsRegex(DeprecationWarning, "Passing Handle"):
|
||||||
res = self.loop.run_in_executor(executor, h)
|
res = self.loop.run_in_executor(executor, h)
|
||||||
self.assertIs(f, res)
|
self.assertIs(f, res)
|
||||||
self.assertTrue(executor.submit.called)
|
self.assertTrue(executor.submit.called)
|
||||||
|
|
|
@ -356,6 +356,8 @@ Library
|
||||||
- Issue #28370: Speedup asyncio.StreamReader.readexactly.
|
- Issue #28370: Speedup asyncio.StreamReader.readexactly.
|
||||||
Patch by Коренберг Марк.
|
Patch by Коренберг Марк.
|
||||||
|
|
||||||
|
- Issue #28371: Deprecate passing asyncio.Handles to run_in_executor.
|
||||||
|
|
||||||
IDLE
|
IDLE
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue