zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import _common
 
# Override the regular excepthook too -- it doesn't change anything either way
# because ipython doesn't use it, but we want to make sure Trio doesn't warn
# about it.
import sys
 
 
def custom_excepthook(*args):
    print("custom running!")
    return sys.__excepthook__(*args)
 
 
sys.excepthook = custom_excepthook
 
import IPython
 
ip = IPython.get_ipython()
 
 
# Set this to some random nonsense
class SomeError(Exception):
    pass
 
 
def custom_exc_hook(etype, value, tb, tb_offset=None):
    ip.showtraceback()
 
 
ip.set_custom_exc((SomeError,), custom_exc_hook)
 
import trio
 
# The custom excepthook should run, because Trio was polite and didn't
# override it
raise trio.MultiError([ValueError(), KeyError()])