MCPcopy Index your code
hub / github.com/python/cpython / _make_invoke_excepthook

Function _make_invoke_excepthook

Lib/threading.py:1301–1349  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1299
1300
1301def _make_invoke_excepthook():
1302 # Create a local namespace to ensure that variables remain alive
1303 # when _invoke_excepthook() is called, even if it is called late during
1304 # Python shutdown. It is mostly needed for daemon threads.
1305
1306 old_excepthook = excepthook
1307 old_sys_excepthook = _sys.excepthook
1308 if old_excepthook is None:
1309 raise RuntimeError("threading.excepthook is None")
1310 if old_sys_excepthook is None:
1311 raise RuntimeError("sys.excepthook is None")
1312
1313 sys_exc_info = _sys.exc_info
1314 local_print = print
1315 local_sys = _sys
1316
1317 def invoke_excepthook(thread):
1318 global excepthook
1319 try:
1320 hook = excepthook
1321 if hook is None:
1322 hook = old_excepthook
1323
1324 args = ExceptHookArgs([*sys_exc_info(), thread])
1325
1326 hook(args)
1327 except Exception as exc:
1328 exc.__suppress_context__ = True
1329 del exc
1330
1331 if local_sys is not None and local_sys.stderr is not None:
1332 stderr = local_sys.stderr
1333 else:
1334 stderr = thread._stderr
1335
1336 local_print("Exception in threading.excepthook:",
1337 file=stderr, flush=True)
1338
1339 if local_sys is not None and local_sys.excepthook is not None:
1340 sys_excepthook = local_sys.excepthook
1341 else:
1342 sys_excepthook = old_sys_excepthook
1343
1344 sys_excepthook(*sys_exc_info())
1345 finally:
1346 # Break reference cycle (exception stored in a variable)
1347 args = None
1348
1349 return invoke_excepthook
1350
1351
1352# The timer class was contributed by Itamar Shtull-Trauring

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…