Skip to content

Commit

Permalink
back to surgically removing frames
Browse files Browse the repository at this point in the history
change test to confirm frame count and bottom-most
watermark frame
  • Loading branch information
belm0 committed Aug 27, 2018
1 parent 18c119d commit c9087e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
15 changes: 7 additions & 8 deletions trio/_core/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import os
import random
import select
import sys
import threading
import traceback
from collections import deque
import collections.abc
from contextlib import contextmanager, closing
Expand Down Expand Up @@ -1378,13 +1378,12 @@ def run_impl(runner, async_fn, args):
final_result = Value(stop_iteration.value)
except BaseException as task_exc:
# Store for later, removing uninteresting top frames:
tb = task_exc.__traceback__
for path, _, _, _ in traceback.extract_tb(tb):
if '/trio/_core/' in path or '/contextvars/' in path:
tb = tb.tb_next
else:
break
final_result = Error(task_exc.with_traceback(tb))
# 1. trio._core._run.run_impl()
# 2. contextvars.Context.run() (< Python 3.7 only)
tb_next = task_exc.__traceback__.tb_next
if sys.version_info < (3, 7):
tb_next = tb_next.tb_next
final_result = Error(task_exc.with_traceback(tb_next))

if final_result is not None:
# We can't call this directly inside the except: blocks above,
Expand Down
8 changes: 5 additions & 3 deletions trio/_core/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1920,9 +1920,11 @@ async def my_child_task():
# is too eager.
#frame = first_exc.__traceback__.tb_frame
#assert frame.f_code is my_child_task.__code__
# ...but we're not there yet. Only as far as open_cancel_scope().
_, _, function, _ = traceback.extract_tb(first_exc.__traceback__)[0]
assert function == 'open_cancel_scope'
# ...but we're not there yet. There are several frames from nursery's
# __aexit__, starting with _nested_child_finished().
frames = traceback.extract_tb(first_exc.__traceback__)
functions = [function for _, _, function, _ in frames]
assert functions[-2:] == ['_nested_child_finished', 'my_child_task']


def test_contextvar_support():
Expand Down

0 comments on commit c9087e9

Please sign in to comment.