]> granicus.if.org Git - python/commitdiff
Issue #28371: Deprecate passing asyncio.Handles to run_in_executor.
authorYury Selivanov <yury@magic.io>
Wed, 5 Oct 2016 22:28:09 +0000 (18:28 -0400)
committerYury Selivanov <yury@magic.io>
Wed, 5 Oct 2016 22:28:09 +0000 (18:28 -0400)
Lib/asyncio/base_events.py
Lib/test/test_asyncio/test_base_events.py
Misc/NEWS

index af66c0a5b6fe9bb57626456df438f1357d9057fd..648b9b9bbc2f5cd516ce4d93f71373f47e201043 100644 (file)
@@ -605,6 +605,9 @@ class BaseEventLoop(events.AbstractEventLoop):
         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)
index 362ab06f399841fae96b741c8f20bec103e54000..a9aba0ffb642a60aa6a34a40bf941b1ff6d3bf69 100644 (file)
@@ -358,7 +358,8 @@ class BaseEventLoopTests(test_utils.TestCase):
         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 @@ class BaseEventLoopTests(test_utils.TestCase):
 
         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)
 
index 354dc59ca23a6937f3711741691971118094b7ca..0a92e6a47c9fd3077357d8c0fd481699e5af7709 100644 (file)
--- 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
 ----