| 67 | |
| 68 | |
| 69 | def _task_print_stack(task, limit, file): |
| 70 | extracted_list = [] |
| 71 | checked = set() |
| 72 | for f in task.get_stack(limit=limit): |
| 73 | lineno = f.f_lineno |
| 74 | co = f.f_code |
| 75 | filename = co.co_filename |
| 76 | name = co.co_name |
| 77 | if filename not in checked: |
| 78 | checked.add(filename) |
| 79 | linecache.checkcache(filename) |
| 80 | line = linecache.getline(filename, lineno, f.f_globals) |
| 81 | extracted_list.append((filename, lineno, name, line)) |
| 82 | |
| 83 | exc = task._exception |
| 84 | if not extracted_list: |
| 85 | print(f'No stack for {task!r}', file=file) |
| 86 | elif exc is not None: |
| 87 | print(f'Traceback for {task!r} (most recent call last):', file=file) |
| 88 | else: |
| 89 | print(f'Stack for {task!r} (most recent call last):', file=file) |
| 90 | |
| 91 | traceback.print_list(extracted_list, file=file) |
| 92 | if exc is not None: |
| 93 | for line in traceback.format_exception_only(exc.__class__, exc): |
| 94 | print(line, file=file, end='') |