-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest.py
More file actions
35 lines (30 loc) · 735 Bytes
/
test.py
File metadata and controls
35 lines (30 loc) · 735 Bytes
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
import threader
import threading
from time import sleep
class AThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.stopped = False # This is the flag we'll use to signal thread termination.
def is_alive(self):
return not self.stopped
def run(self):
try:
while True:
print ("I'm running...and I'll never end!")
sleep(5)
except Exception as e:
raise e
finally:
self.stopped = true
def end(self):
if self.is_alive():
threader.killThread(self.ident)
self.stopped = True
runMe = AThread()
runMe.start()
sleep(10)
runMe.end()
print("Ended.")
# We'll wait here to check that the thread has indeed ended.
# No more messages should print after this line.
sleep(20)