MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / print_exc

Method print_exc

tools/python-3.11.9-amd64/Lib/timeit.py:139–164  ·  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

(self, file=None)

Source from the content-addressed store, hash-verified

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

Callers 15

mainFunction · 0.95
checkMethod · 0.80
mainFunction · 0.80
handle_errorMethod · 0.80
handleMethod · 0.80
cleanupMethod · 0.80
handle_errorMethod · 0.80
handle_errorMethod · 0.80
localcallMethod · 0.80

Calls 1

splitMethod · 0.45

Tested by 1

cleanupMethod · 0.64