import linecacheimport tracebackfrom . import base_futuresfrom . import coroutinesdef _task_repr_info(task):info = base_futures._future_repr_info(task)if task._must_cancel:# replace statusinfo[0] = 'cancelling'coro = coroutines._format_coroutine(task._coro)info.insert(1, f'coro=<{coro}>')if task._fut_waiter is not None:info.insert(2, f'wait_for={task._fut_waiter!r}')return infodef _task_get_stack(task, limit):frames = []try:# 'async def' coroutinesf = task._coro.cr_frameexcept AttributeError:f = task._coro.gi_frameif f is not None:while f is not None:if limit is not None:if limit <= 0:breaklimit -= 1frames.append(f)f = f.f_backframes.reverse()elif task._exception is not None:tb = task._exception.__traceback__while tb is not None:if limit is not None:if limit <= 0:breaklimit -= 1frames.append(tb.tb_frame)tb = tb.tb_nextreturn framesdef _task_print_stack(task, limit, file):extracted_list = []checked = set()for f in task.get_stack(limit=limit):lineno = f.f_linenoco = f.f_codefilename = co.co_filenamename = co.co_nameif filename not in checked:checked.add(filename)linecache.checkcache(filename)line = linecache.getline(filename, lineno, f.f_globals)extracted_list.append((filename, lineno, name, line))exc = task._exceptionif not extracted_list:print(f'No stack for {task!r}', file=file)elif exc is not None:print(f'Traceback for {task!r} (most recent call last):', file=file)else:print(f'Stack for {task!r} (most recent call last):', file=file)traceback.print_list(extracted_list, file=file)if exc is not None:for line in traceback.format_exception_only(exc.__class__, exc):print(line, file=file, end='')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。