-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread_sample.py
47 lines (35 loc) · 953 Bytes
/
thread_sample.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import threading
import time
class ThreadA(threading.Thread):
def __init__(self, record=False, rec_time=10):
super(ThreadA, self).__init__()
self.setDaemon(True)
self.count = 0
def run(self):
while True:
self.count += 1
time.sleep(1)
print("threadA " + str(self.count))
class ThreadB(threading.Thread):
def __init__(self, record=False, rec_time=10):
super(ThreadB, self).__init__()
self.setDaemon(True)
self.count = 0
def run(self):
while True:
self.count += 1
time.sleep(2)
print("threadB " + str(self.count))
if __name__ == '__main__':
print("start events")
a = ThreadA()
a.setDaemon(True)
a.start()
b = ThreadB()
b.setDaemon(True)
b.start()
while True:
c = 1