-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest2.py
executable file
·62 lines (58 loc) · 1.58 KB
/
test2.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
#!/usr/bin/env python3.6
#cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True, profile=False, c_string_type=bytes
import os
from sys import exit
from time import sleep
import concurrent.futures
class TestClass:
def __init__(self):
self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=5)
self.i = 0
self.j1 = 0
self.j2 = 0
self.j3 = 0
def func1(self):
self.j1 += 1
print("j1", self.j1)
while self.j1:
#while True:
print("func1")
self.i += 1
sleep(1)
def func2(self):
self.j2 += 1
print("j2", self.j2)
while True:
print("func2", self.i)
sleep(2)
def func3(self):
self.j3 += 1
print("j3", self.j3)
while True:
print("func3", self.i)
sleep(4)
self.j1 = 0
def run(self):
print("run1")
a=self.executor.submit(self.func1)
print("run2")
self.executor.submit(self.func2)
print("run3")
self.executor.submit(self.func3)
print("run4")
self.executor.submit(self.func3)
print("run5")
self.executor.submit(self.func3)
print("run6")
sleep(10)
#print(a.cancel())
a.result()
self.executor.submit(self.func3)
print("run7")
self.executor.submit(self.func3)
print("run8")
self.executor.submit(self.func3)
print("run9")
if (__name__ == '__main__'):
testclass = TestClass()
testclass.run()