MCPcopy Index your code
hub / github.com/RustPython/RustPython / print_exc

Method print_exc

Lib/timeit.py:136–161  ·  view source on GitHub ↗

Helper to print a traceback from the timed code. Typical use: t = Timer(...) # outside the try/except try: t.timeit(...) # or t.repeat(...) except: t.print_exc() The advantage over the standard traceback

(self, file=None)

Source from the content-addressed store, hash-verified

134 self.inner = local_ns["inner"]
135
136 def print_exc(self, file=None):
137 """Helper to print a traceback from the timed code.
138
139 Typical use:
140
141 t = Timer(...) # outside the try/except
142 try:
143 t.timeit(...) # or t.repeat(...)
144 except:
145 t.print_exc()
146
147 The advantage over the standard traceback is that source lines
148 in the compiled template will be displayed.
149
150 The optional file argument directs where the traceback is
151 sent; it defaults to sys.stderr.
152 """
153 import linecache, traceback
154 if self.src is not None:
155 linecache.cache[dummy_src_name] = (len(self.src),
156 None,
157 self.src.split("\n"),
158 dummy_src_name)
159 # else the source is already stored somewhere else
160
161 traceback.print_exc(file=file)
162
163 def timeit(self, number=default_number):
164 """Time 'number' executions of the main statement.

Callers 15

mainFunction · 0.95
test_print_excMethod · 0.95
start_new_threadFunction · 0.80
start_joinable_threadFunction · 0.80
mainFunction · 0.80
handle_errorMethod · 0.80
handleMethod · 0.80
_run_childMethod · 0.80

Calls 2

lenFunction · 0.85
splitMethod · 0.45

Tested by 7

test_print_excMethod · 0.76
_run_childMethod · 0.64
cleanupMethod · 0.64
child_fnFunction · 0.64