-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
72 lines (61 loc) · 2.07 KB
/
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
'''
Run the program.
'''
import logging
import settings
'''
Subscribe to the server command on multiple servers, then pass the resultant messages
into a queue for processing.
'''
from sys import exit
from multiprocessing import Process, Queue
import logging
from ws_connection.initialize_ws import start_websocket_loop
from process_responses.process_output import start_output_processing
from notifications.notification_watcher import start_notifications
from misc import generate_tables
def start_bot(settings):
'''
Start multiprocessing processes.
'''
processes = []
message_queue = Queue()
notification_queue = Queue()
table_stock = generate_tables.create_table_stock(settings)
table_validator = generate_tables.create_table_validation(settings)
args_d = {
'settings': settings,
'table_stock': table_stock,
'table_validator': table_validator,
'message_queue': message_queue,
'notification_queue': notification_queue,
}
processes.append(Process(target=start_websocket_loop, args=(args_d,)))
processes.append(Process(target=start_output_processing, args=(args_d,)))
processes.append(Process(target=start_notifications, args=(args_d,)))
while True:
try:
for process in processes:
process.start()
for process in processes:
process.join()
logging.warning("Initial multiprocessing list is running.")
except (KeyboardInterrupt):
logging.critical("Keyboard interrupt detected, exiting.")
logging.critical("Final multiprocessing cleanup is running.")
finally:
logging.critical("All threads have been closed.")
exit(0)
def set_logging():
'''
Set logging params.
'''
logging.basicConfig(
filename=settings.LOG_FILE,
level=settings.LOG_LEVEL,
datefmt="%Y-%m-%d %H:%M:%S",
format='%(asctime)s %(levelname)s: %(module)s - %(funcName)s (%(lineno)d): %(message)s',
)
if __name__ == '__main__':
set_logging()
start_bot(settings)