bpo-32250: Implement asyncio.current_task() and asyncio.all_tasks() by asvetlov · Pull Request #4799 · python/cpython (original) (raw)
overall LGTM.
Please apply this diff to fix tests in refleak mode:
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 31d4ed649c..f6a1ac6f31 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -2202,6 +2202,8 @@ class BaseTaskIntrospectionTests: self.assertEqual(asyncio.all_tasks(loop), set()) self._register_task(loop, task) self.assertEqual(asyncio.all_tasks(loop), {task})
self._unregister_task(loop, task)
def test__enter_task(self): task = mock.Mock()self.assertEqual(asyncio.all_tasks(loop), set())
@@ -2209,6 +2211,7 @@ class BaseTaskIntrospectionTests: self.assertIsNone(asyncio.current_task(loop)) self._enter_task(loop, task) self.assertIs(asyncio.current_task(loop), task)
def test__enter_task_failure(self): task1 = mock.Mock()self._leave_task(loop, task)
@@ -2218,6 +2221,7 @@ class BaseTaskIntrospectionTests: with self.assertRaises(RuntimeError): self._enter_task(loop, task2) self.assertIs(asyncio.current_task(loop), task1)
def test__leave_task(self): task = mock.Mock()self._leave_task(loop, task1)
@@ -2234,6 +2238,7 @@ class BaseTaskIntrospectionTests: with self.assertRaises(RuntimeError): self._leave_task(loop, task2) self.assertIs(asyncio.current_task(loop), task1)
def test__leave_task_failure2(self): task = mock.Mock()self._leave_task(loop, task1)
@@ -2246,13 +2251,13 @@ class BaseTaskIntrospectionTests: task = mock.Mock() loop = mock.Mock() self._register_task(loop, task)
self._unregister_task(loop, task)
def test__unregister_task_not_registered(self): task = mock.Mock() loop = mock.Mock()asyncio._unregister_task(loop, task) self.assertEqual(asyncio.all_tasks(loop), set())
self._unregister_task(loop, task)
asyncio._unregister_task(loop, task) self.assertEqual(asyncio.all_tasks(loop), set())