-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyBase.py
68 lines (43 loc) · 1.36 KB
/
MyBase.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
###########################################################################
#
# MyBase.py
# base class definition
#
# Jinserk Baik <[email protected]>
#
# This source code is distributed under BSD License.
# The use of this code implies you agree the license.
#
# Copyright (c) 2013, Jinserk Baik All rights reserved.
#
###########################################################################
import sys, cgitb
import datetime as dt
def _catch_errors():
sys.excepthook = _my_except_hook
def _my_except_hook(etype, evalue, etraceback):
_do_verbose_exception((etype, evalue, etraceback))
def _do_verbose_exception(exc_info=None):
if exc_info is None:
exc_info = sys.exc_info()
txt = cgitb.text(exc_info)
d = dt.datetime.now()
p = (d.year, d.month, d.day, d.hour, d.minute, d.second)
filename = "ErrorDump-%d%02d%02d-%02d%02d%02d.txt" % p
open(filename,'w').write(txt)
print "** EXITING on unhandled exception - See %s" % filename
sys.exit(1)
class MyBase:
def __init__(self, debug=False):
self._debug_flag = debug
def __del__(self):
pass
def _debug(self, *args):
if self._debug_flag:
try:
print ' '.join(args)
except Exception as e:
print args
if __name__ == '__main__':
pass