forked from ZhuoZhuoCrayon/pythonCrawler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13.1thread_ood.py
More file actions
43 lines (34 loc) · 911 Bytes
/
13.1thread_ood.py
File metadata and controls
43 lines (34 loc) · 911 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
36
37
38
39
40
41
42
43
import threading
import time
# 写一个类,继承自threading.Thread
class Singthread(threading.Thread):
def __init__(self, name, a):
super().__init__()
self.name = name
self.a = a
def run(self):
for x in range(1, 6):
print('I am sing')
time.sleep(1)
class Dancethread(threading.Thread):
def __init__(self, name, a):
super().__init__()
self.name = name
self.a = a
def run(self):
for x in range(1, 6):
print('I am dancing')
time.sleep(1)
def main():
# create thread
tsing = Singthread('sing', 'cai')
tdance = Dancethread('dance', 'crayon')
# start thread
tsing.start()
tdance.start()
# waiting thread end
tsing.join()
tdance.join()
print('I am Main')
if __name__ == '__main__':
main()