From 0de3de6cbfe034654dc03f3808de0c25e28a0c38 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Wed, 5 Oct 2016 18:28:09 -0400 Subject: [PATCH] Issue #28371: Deprecate passing asyncio.Handles to run_in_executor. --- Lib/asyncio/base_events.py | 3 +++ Lib/test/test_asyncio/test_base_events.py | 9 ++++++--- Misc/NEWS | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index af66c0a5b6f..648b9b9bbc2 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -605,6 +605,9 @@ def run_in_executor(self, executor, func, *args): if isinstance(func, events.Handle): assert not args assert not isinstance(func, events.TimerHandle) + warnings.warn( + "Passing Handle to loop.run_in_executor() is deprecated", + DeprecationWarning) if func._cancelled: f = self.create_future() f.set_result(None) diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py index 362ab06f399..a9aba0ffb64 100644 --- a/Lib/test/test_asyncio/test_base_events.py +++ b/Lib/test/test_asyncio/test_base_events.py @@ -358,7 +358,8 @@ def cb(): h = asyncio.Handle(cb, (), self.loop) h.cancel() - f = self.loop.run_in_executor(None, h) + with self.assertWarnsRegex(DeprecationWarning, "Passing Handle"): + f = self.loop.run_in_executor(None, h) self.assertIsInstance(f, asyncio.Future) self.assertTrue(f.done()) self.assertIsNone(f.result()) @@ -373,12 +374,14 @@ def cb(): self.loop.set_default_executor(executor) - res = self.loop.run_in_executor(None, h) + with self.assertWarnsRegex(DeprecationWarning, "Passing Handle"): + res = self.loop.run_in_executor(None, h) self.assertIs(f, res) executor = mock.Mock() executor.submit.return_value = f - res = self.loop.run_in_executor(executor, h) + with self.assertWarnsRegex(DeprecationWarning, "Passing Handle"): + res = self.loop.run_in_executor(executor, h) self.assertIs(f, res) self.assertTrue(executor.submit.called) diff --git a/Misc/NEWS b/Misc/NEWS index 354dc59ca23..0a92e6a47c9 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -356,6 +356,8 @@ Library - Issue #28370: Speedup asyncio.StreamReader.readexactly. Patch by Коренберг Марк. +- Issue #28371: Deprecate passing asyncio.Handles to run_in_executor. + IDLE ----