from . import base_futures
def _task_repr_info(task):
info = base_futures._future_repr_info(task)
info.insert(1, 'name=%r' % task.get_name())
coro = coroutines._format_coroutine(task._coro)
info.insert(2, f'coro=<{coro}>')
if task._fut_waiter is not None:
info.insert(3, f'wait_for={task._fut_waiter!r}')
def _task_get_stack(task, limit):
if hasattr(task._coro, 'cr_frame'):
# case 1: 'async def' coroutines
elif hasattr(task._coro, 'gi_frame'):
# case 2: legacy coroutines
elif hasattr(task._coro, 'ag_frame'):
# case 3: async generators
# case 4: unknown objects
elif task._exception is not None:
tb = task._exception.__traceback__
frames.append(tb.tb_frame)
def _task_print_stack(task, limit, file):
for f in task.get_stack(limit=limit):
filename = co.co_filename
if filename not in checked:
linecache.checkcache(filename)
line = linecache.getline(filename, lineno, f.f_globals)
extracted_list.append((filename, lineno, name, line))
print(f'No stack for {task!r}', file=file)
print(f'Traceback for {task!r} (most recent call last):', file=file)
print(f'Stack for {task!r} (most recent call last):', file=file)
traceback.print_list(extracted_list, file=file)
for line in traceback.format_exception_only(exc.__class__, exc):
print(line, file=file, end='')