-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcfiler_debug.py
More file actions
136 lines (94 loc) · 3.59 KB
/
cfiler_debug.py
File metadata and controls
136 lines (94 loc) · 3.59 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import sys
import os
import time
import threading
import traceback
import ctypes
import ckit
import cfiler_resource
#--------------------------------------------------------------------
block_detect_thread = None
def enableBlockDetector():
global block_detect_thread
# インタプリタが長時間ブロックしたときに呼ばれる関数
def blockDetector():
print( "" )
print( "Block detected:" )
traceback.print_stack()
print( "" )
ckit.enableBlockDetector( blockDetector )
# インタプリタが長時間ブロックしたことを検出するために、
# 定期的にインタプリタを動かし続ける
class BlockDetectThread( threading.Thread ):
def __init__(self):
threading.Thread.__init__(self)
self.canceled = False
def run(self):
ckit.setBlockDetector()
while not self.canceled:
time.sleep(0.1)
def cancel(self):
self.canceled = True
block_detect_thread = BlockDetectThread()
block_detect_thread.start()
ckit.setBlockDetector()
def disableBlockDetector():
global block_detect_thread
if block_detect_thread:
block_detect_thread.cancel()
block_detect_thread.join()
block_detect_thread = None
#--------------------------------------------------------------------
exit_timeout_thread = None
def _forceAbort():
# 残存しているスレッドの情報
message = "Remaining threads:\n"
message += "\n"
for thread in threading.enumerate():
message += " %s\n" % str(thread)
message += "\n"
for threadId, stack in sys._current_frames().items():
message += "ThreadID: %s\n" % threadId
for filename, lineno, name, line in traceback.extract_stack(stack):
message += ' File: "%s", line %d, in %s\n' % (filename, lineno, name)
if line:
message += " %s\n" % (line.strip())
message += "\n"
ctypes.windll.user32.MessageBoxW( 0, message, cfiler_resource.cfiler_appname, 0 )
os.abort()
def enableExitTimeout():
global exit_timeout_thread
# インタプリタが長時間ブロックしたことを検出するために、
# 定期的にインタプリタを動かし続ける
class ExitTimeoutThread( threading.Thread ):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
def run(self):
ckit.setBlockDetector()
self.event.wait(10.0)
if not self.event.isSet():
_forceAbort()
def cancel(self):
self.event.set()
exit_timeout_thread = ExitTimeoutThread()
exit_timeout_thread.start()
def disableExitTimeout():
global exit_timeout_thread
if exit_timeout_thread:
exit_timeout_thread.cancel()
exit_timeout_thread.join()
exit_timeout_thread = None
#--------------------------------------------------------------------
print_errorinfo_enabled = False
def enablePrintErrorInfo():
global print_errorinfo_enabled
print_errorinfo_enabled = True
def disablePrintErrorInfo():
global print_errorinfo_enabled
print_errorinfo_enabled = False
def printErrorInfo():
if print_errorinfo_enabled:
print( "Debug: ", end="" )
traceback.print_exc()
#--------------------------------------------------------------------