-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultithread_test.py
More file actions
51 lines (40 loc) · 1.06 KB
/
multithread_test.py
File metadata and controls
51 lines (40 loc) · 1.06 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
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
from threading import Thread
import time
class TestThread(Thread):
"""
A threading test
"""
def __init__(self, number):
"""Инициализация потока"""
Thread.__init__(self)
self.number = number
self.counts = 0
self.total_counts = 0
def run(self):
"""Запуск потока"""
t0 = time.time()
while True:
if time.time() - t0 > 10:
break
self.counts += 1
self.total_counts += self.counts
def create_threads(list_threads, a):
"""
Создаем группу потоков
"""
for i in range(a):
number = i+1
my_thread = TestThread(number)
list_threads.append(my_thread)
my_thread.start()
if __name__ == "__main__":
all_threads = []
a = 36
create_threads(all_threads, a)
time.sleep(11)
counts = 0
for item in all_threads:
counts += item.counts
# print(item.counts, end="\n")
print(counts, counts/a)