-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.py
116 lines (98 loc) · 4.21 KB
/
app.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
112
113
114
115
116
try:
from Modules import DataCleaning, DataCollection
import threading
import var
from time import sleep
except Exception as e:
exit("Exception: " + str(e))
# Driver Function
def _main():
var._debug and print("App Starting...")
# Data Collection
dataCollection = DataCollection()
dataCleaning = DataCleaning()
threads = []
while True:
var._debug and print("Threads Running: ", threading.active_count())
try:
# thread 1
thread = threading.Thread(None, target=dataCleaning._cleaning, args=(
{"_translated_text_polarity": None},), daemon=True)
thread.start()
threads.append(thread)
var._debug and print("A Thread => ", threading.active_count())
# Thread 2
sleep(var._sleep_time_small) # small time
thread = threading.Thread(
None, target=dataCollection._collect, args=(var._model_arg_1,), daemon=True)
thread.start()
threads.append(thread)
var._debug and print("A Thread => ", threading.active_count())
# Thread 2
sleep(var._sleep_time_small) # small time
thread = threading.Thread(
None, target=dataCollection._collect, args=(var._model_arg_2,), daemon=True)
thread.start()
threads.append(thread)
var._debug and print("A Thread => ", threading.active_count())
# Thread 2
sleep(var._sleep_time_small) # small time
thread = threading.Thread(
None, target=dataCollection._collect, args=(var._model_arg_3,), daemon=True)
thread.start()
threads.append(thread)
var._debug and print("A Thread => ", threading.active_count())
# Main Thread
var._active_print and print("Main Thread to Work:")
sleep(var._sleep_time_small) # small time
dataCleaning._remove_duplicates()
var._debug and print("A Thread => ", threading.active_count())
# All Joins
sleep(var._sleep_time_small) # small time
var._active_print and print(
"Running Main Thread: ", threading.current_thread())
except KeyboardInterrupt:
var._debug and print("Keyboard Interrupt")
break
except Exception as e:
var._debug and print("App Error: ", e)
var._debug and print("Active Threads => ", threading.active_count())
sleep(var._sleep_time_small) # small time
for thread in threads:
print(thread.name)
var._debug and print("Closing Threads:", threading.active_count())
sleep(var._sleep_time_small) # small time
thread.join()
try:
for thread in threading.enumerate():
if thread.name != "MainThread":
print(thread.name)
var._debug and print("Closing Enumerate Threads:", str(
thread.name+" ("+threading.active_count()+") "))
sleep(var._sleep_time_small) # small time
thread.join()
except Exception as e:
print("Eception:", e)
print(thread.name)
sleep(var._sleep_time_small) # small time
var._debug and print("Active Threads => ", threading.active_count())
sleep(var._sleep_time_small) # small time
print("Threads Running: ", threading.enumerate())
sleep(var._sleep_time_small) # small time
var._active_print and print(
"Running Main Outer Thread: ", threading.current_thread())
# Check ENV
if var._deployment_env == False:
var._debug and print("Developer Environment!!")
break
for thread in threading.enumerate():
if thread.name != "MainThread":
var._debug and print("Cleaning Enumerate Threads:", str(
thread.name+" ("+threading.active_count()+") "))
sleep(var._sleep_time_small) # small time
thread.join()
var._debug and print("App Closed.")
return "Back to Main!!"
# Main Method
if __name__ == '__main__':
exit("Exit with " + _main())