mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
asyncio, Tulip issue 137: In debug mode, save traceback where Future, Task and
Handle objects are created. Pass the traceback to call_exception_handler() in the 'source_traceback' key. The traceback is truncated to hide internal calls in asyncio, show only the traceback from user code. Add tests for the new source_traceback, and a test for the 'Future/Task exception was never retrieved' log.
This commit is contained in:
parent
bbd96c6f47
commit
80f53aa9a0
8 changed files with 180 additions and 26 deletions
|
@ -1546,6 +1546,7 @@ class TaskTests(test_utils.TestCase):
|
|||
raise Exception("code never reached")
|
||||
|
||||
mock_handler = mock.Mock()
|
||||
self.loop.set_debug(True)
|
||||
self.loop.set_exception_handler(mock_handler)
|
||||
|
||||
# schedule the task
|
||||
|
@ -1560,6 +1561,7 @@ class TaskTests(test_utils.TestCase):
|
|||
# remove the future used in kill_me(), and references to the task
|
||||
del coro.gi_frame.f_locals['future']
|
||||
coro = None
|
||||
source_traceback = task._source_traceback
|
||||
task = None
|
||||
|
||||
# no more reference to kill_me() task: the task is destroyed by the GC
|
||||
|
@ -1570,6 +1572,7 @@ class TaskTests(test_utils.TestCase):
|
|||
mock_handler.assert_called_with(self.loop, {
|
||||
'message': 'Task was destroyed but it is pending!',
|
||||
'task': mock.ANY,
|
||||
'source_traceback': source_traceback,
|
||||
})
|
||||
mock_handler.reset_mock()
|
||||
|
||||
|
@ -1604,6 +1607,17 @@ class TaskTests(test_utils.TestCase):
|
|||
|
||||
self.assertRegex(message, re.compile(regex, re.DOTALL))
|
||||
|
||||
def test_task_source_traceback(self):
|
||||
self.loop.set_debug(True)
|
||||
|
||||
task = asyncio.Task(coroutine_function(), loop=self.loop)
|
||||
lineno = sys._getframe().f_lineno - 1
|
||||
self.assertIsInstance(task._source_traceback, list)
|
||||
self.assertEqual(task._source_traceback[-1][:3],
|
||||
(__file__,
|
||||
lineno,
|
||||
'test_task_source_traceback'))
|
||||
|
||||
|
||||
class GatherTestsBase:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue