-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThread.py
More file actions
40 lines (32 loc) · 1.01 KB
/
Thread.py
File metadata and controls
40 lines (32 loc) · 1.01 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
import sys
import threading
class Thread(threading.Thread):
def __init__(self, *args, **keywords):
threading.Thread.__init__(self, *args, **keywords)
self.__killed = False
self.__Parent = None
def start(self):
self.__run_backup = self.run
self.run = self.__run
threading.Thread.start(self)
def __run(self):
sys.settrace(self.__globaltrace)
self.__run_backup()
self.run = self.__run_backup
def __globaltrace(self, frame, event, arg):
if event == 'call':
return self.__localtrace
else:
return None
def __localtrace(self, frame, event, arg):
if self.__killed:
if event == 'line':
raise SystemExit()
if self.__Parent is not None:
if not self.__Parent.is_alive():
raise SystemExit()
return self.__localtrace
def Bind(self, Parent):
self.__Parent = Parent
def kill(self):
self.__killed = True