Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Commit 99ebe37

Browse files
committed
Raise DeprecationWarning when run_in_executor is called with a Handle
(Closes issue #334)
1 parent b0e7438 commit 99ebe37

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

asyncio/base_events.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ def run_in_executor(self, executor, func, *args):
605605
if isinstance(func, events.Handle):
606606
assert not args
607607
assert not isinstance(func, events.TimerHandle)
608+
warnings.warn(
609+
"Passing Handle to loop.run_in_executor() is deprecated",
610+
DeprecationWarning)
608611
if func._cancelled:
609612
f = self.create_future()
610613
f.set_result(None)

tests/test_base_events.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ def cb():
358358
h = asyncio.Handle(cb, (), self.loop)
359359
h.cancel()
360360

361-
f = self.loop.run_in_executor(None, h)
361+
with self.assertWarnsRegex(DeprecationWarning, "Passing Handle"):
362+
f = self.loop.run_in_executor(None, h)
362363
self.assertIsInstance(f, asyncio.Future)
363364
self.assertTrue(f.done())
364365
self.assertIsNone(f.result())
@@ -373,12 +374,14 @@ def cb():
373374

374375
self.loop.set_default_executor(executor)
375376

376-
res = self.loop.run_in_executor(None, h)
377+
with self.assertWarnsRegex(DeprecationWarning, "Passing Handle"):
378+
res = self.loop.run_in_executor(None, h)
377379
self.assertIs(f, res)
378380

379381
executor = mock.Mock()
380382
executor.submit.return_value = f
381-
res = self.loop.run_in_executor(executor, h)
383+
with self.assertWarnsRegex(DeprecationWarning, "Passing Handle"):
384+
res = self.loop.run_in_executor(executor, h)
382385
self.assertIs(f, res)
383386
self.assertTrue(executor.submit.called)
384387

0 commit comments

Comments
 (0)