Skip to content

Commit

Permalink
Restored the frame hiding hack
Browse files Browse the repository at this point in the history
Turns out it this is still needed on PyPy.
  • Loading branch information
agronholm committed Jan 22, 2022
1 parent 8ffc1b1 commit eff710b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions trio/_core/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ def _public(fn):
_r = random.Random()


# On CPython, Context.run() is implemented in C and doesn't show up in
# tracebacks. On PyPy, it is implemented in Python and adds 1 frame to tracebacks.
def _count_context_run_tb_frames():
def function_with_unique_name_xyzzy():
1 / 0

ctx = copy_context()
try:
ctx.run(function_with_unique_name_xyzzy)
except ZeroDivisionError as exc:
tb = exc.__traceback__
# Skip the frame where we caught it
tb = tb.tb_next
count = 0
while tb.tb_frame.f_code.co_name != "function_with_unique_name_xyzzy":
tb = tb.tb_next
count += 1
return count


CONTEXT_RUN_TB_FRAMES = _count_context_run_tb_frames()


@attr.s(frozen=True, slots=True)
class SystemClock:
# Add a large random offset to our clock to ensure that if people
Expand Down

0 comments on commit eff710b

Please sign in to comment.