forked from Henryhaohao/Bilibili_video_download
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_main.py
96 lines (70 loc) · 1.89 KB
/
test_main.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
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
# -*- coding: utf-8 -*-
"""
Created on Fri May 31 16:45:03 2019
@author: wenyz
"""
from multiprocessing import Process, Queue,cpu_count
import time
import threading
from queue import Queue
class test:
def __init__(self,a,b,c):
self.a =a
self.b = b
self.c = c
ooos = []
for i in range(10):
ooos.append(Ooos(self))
self.ooos = ooos
def print_self(self):
for sss in self.ooos:
print('self print {}'.format(sss.status))
class Ooos:
def __init__(self,test):
self.status = 0
self.test = test
def update(ooos):
time.sleep(5)
print('update ooos status')
ooos.status = 1
for eee in ooos.test.ooos:
print(eee.status)
print('='*70)
class update_thread(threading.Thread):
def __init__(self,quq):
threading.Thread.__init__(self)
self.quq = quq
self.isDaemon = True
def run(self):
while True:
if not self.quq.empty():
ooos = self.quq.get()
update(ooos)
class keep_print(threading.Thread):
def __init__(self,test):
threading.Thread.__init__(self)
self.test = test
self.isDaemon = True
def run(self):
while True:
time.sleep(6)
#self.test.print_self()
for sss in self.test.ooos:
print('keep print {}'.format(sss.status))
if __name__ == '__main__':
current = test('aaa','bbb','ccc')
qqq = Queue(10)
for aa in current.ooos:
qqq.put(aa)
#qqq.put(None)
threads = []
gg = keep_print(current)
gg.start()
for i in range(3):
tt = update_thread(qqq)
tt.start()
threads.append(tt)
[ts.join() for ts in threads]
#gg.join()
qqq.join()
print("finished")