Skip to content

Commit 3eb7af0

Browse files
committed
back to surgically removing frames
change test to confirm frame count and bottom-most watermark frame
1 parent 18c119d commit 3eb7af0

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

trio/_core/_run.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import os
44
import random
55
import select
6+
import sys
67
import threading
7-
import traceback
88
from collections import deque
99
import collections.abc
1010
from contextlib import contextmanager, closing
@@ -1378,13 +1378,12 @@ def run_impl(runner, async_fn, args):
13781378
final_result = Value(stop_iteration.value)
13791379
except BaseException as task_exc:
13801380
# Store for later, removing uninteresting top frames:
1381-
tb = task_exc.__traceback__
1382-
for path, _, _, _ in traceback.extract_tb(tb):
1383-
if '/trio/_core/' in path or '/contextvars/' in path:
1384-
tb = tb.tb_next
1385-
else:
1386-
break
1387-
final_result = Error(task_exc.with_traceback(tb))
1381+
# 1. trio._core._run.run_impl()
1382+
# 2. contextvars.Context.run() (< Python 3.7 only)
1383+
tb_next = task_exc.__traceback__.tb_next
1384+
if sys.version_info < (3, 7):
1385+
tb_next = tb_next.tb_next
1386+
final_result = Error(task_exc.with_traceback(tb_next))
13881387

13891388
if final_result is not None:
13901389
# We can't call this directly inside the except: blocks above,

trio/_core/tests/test_run.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,9 +1920,12 @@ async def my_child_task():
19201920
# is too eager.
19211921
#frame = first_exc.__traceback__.tb_frame
19221922
#assert frame.f_code is my_child_task.__code__
1923-
# ...but we're not there yet. Only as far as open_cancel_scope().
1924-
_, _, function, _ = traceback.extract_tb(first_exc.__traceback__)[0]
1925-
assert function == 'open_cancel_scope'
1923+
# ...but we're not there yet. There are 3 frames from the nursery
1924+
# __aexit__, starting with _nested_child_finished().
1925+
frames = traceback.extract_tb(first_exc.__traceback__)
1926+
assert len(frames) == 4
1927+
_, _, function, _ = frames[2]
1928+
assert function == '_nested_child_finished'
19261929

19271930

19281931
def test_contextvar_support():

0 commit comments

Comments
 (0)