Completed
Push — master ( f2913e...ec1efc )
by Thomas
14:28
created

intercept.trace_interceptor()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
# encoding: utf-8
2
"""
3
debug.py
4
5
Created by Thomas Mangin on 2011-03-29.
6
Copyright (c) 2009-2017 Exa Networks. All rights reserved.
7
License: 3-clause BSD. (See the COPYRIGHT file)
8
"""
9
10
import os
11
import sys
12
import pdb
13
14
from exabgp.debug.report import format_panic
15
16
17
def bug_report(dtype, value, trace):
18
    sys.stdout.flush()
19
    sys.stderr.flush()
20
    print(format_panic(dtype, value, trace))
21
    sys.stdout.flush()
22
23
24
def intercept(dtype, value, trace):
25
    bug_report(dtype, value, trace)
26
    if os.environ.get('PDB', None) not in [None, '0', '']:
27
        pdb.pm()
28
29
30
def trace_interceptor():
31
    sys.excepthook = intercept
32
33