-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxt_libx.py
111 lines (59 loc) · 2.38 KB
/
xt_libx.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/python3
import subprocess
import threading
import time
class xt:
def __init__(self,input_var_values,min_values_varName,command_temp,verbose):
self.input_vars_values = input_var_values
self.min_val_varname = min_values_varName
self.command_temp = command_temp
self.verbose = verbose
def sub_call(self,command,ex_signal):
if ex_signal:
return
if self.verbose == True:
p = subprocess.run(command,shell=True,capture_output=True,text=True)
print(p.stdout)
else:
subprocess.run(command,shell=True,capture_output=True)
def command_gen(self,value_index):
command = self.command_temp
for var in self.input_vars_values:
command = str(command).replace(f"${var}",self.input_vars_values[var][value_index])
return command
def Thread1(self,threads_num,sleep_time):
i = 0
while i < len(self.input_vars_values[self.min_val_varname]):
try:
self.input_vars_values[self.min_val_varname][i+1]
except Exception as ex:
break
ex_signal = False
threads = []
for _ in range(threads_num):
command = self.command_gen(i)
t = threading.Thread(target=self.sub_call,args=[command,ex_signal])
t.start()
threads.append(t)
try:
self.input_vars_values[self.min_val_varname][i+1]
i+=1
except Exception as ex:
ex_signal = True
for thread in threads:
thread.join()
time.sleep(sleep_time)
def Thread2(self,threads_num,sleep_time,thread_loops_num):
i = 0
while i < thread_loops_num:
ex_signal = False
threads = []
for _ in range(threads_num):
command = self.command_temp
t = threading.Thread(target=self.sub_call,args=[command,ex_signal])
t.start()
threads.append(t)
for thread in threads:
thread.join()
i+=1
time.sleep(sleep_time)