-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMainFunction.py
executable file
·88 lines (75 loc) · 2.27 KB
/
MainFunction.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
#!/usr/bin/python3
# Importing necessary modules
from audioop import mul
import multiprocessing as mp
import socket
# Imports the GUIWindow
from PythonFiles.GUIWindow import GUIWindow
from PythonFiles.utils.SUBClient import SUBClient
# Creates a task of creating the GUIWindow
def task_GUI(conn, queue):
# creates the main_window as an instantiation of GUIWindow
main_window = GUIWindow(conn, queue)
# Creates a task of creating the SUBClient
def task_SUBClient(conn, queue):
# Creates the SUBSCRIBE Socket Client
sub_client = SUBClient(conn, queue)
def run():
# Creates a Pipe for the SUBClient to talk to the GUI Window
conn_SUB, conn_GUI = mp.Pipe()
queue = mp.Queue()
# Turns creating the GUI and creating the SUBClient tasks into processes
process_GUI = mp.Process(target = task_GUI, args=(conn_GUI, queue,))
process_SUBClient = mp.Process(target = task_SUBClient, args = (conn_SUB, queue,))
# Starts the processes
process_GUI.start()
process_SUBClient.start()
# Should hold the code at this line until the GUI process ends
process_GUI.join()
try:
conn_SUB.close()
conn_GUI.close()
except:
print("Pipe close is unnecessary.")
try:
# Cleans up the SUBClient process
process_SUBClient.terminate()
except:
print("Terminate is unnecessary.")
pass
if __name__ == "__main__":
print(socket.gethostname())
###### Example code to branch between the different GUIS #####
# visual_GUI_computers = [
# computer_1,
# computer_2,
# etc.
# ]
# wagon_GUI_computers = [
# computer_3,
# computer_4,
# etc.
# ]
# engine_GUI_computers = [
# computer_5,
# computer_6,
# etc.
# ]
# current_computer = socket.gethostname()
# for computer in visual_GUI_computers:
# if current_computer == computer:
# run_visual_GUI()
# else:
# pass
# for computer in wagon_GUI_computers:
# if current_computer == computer:
# run_wagon_GUI()
# else:
# pass
# for computer in engine_GUI_computers:
# if current_computer == computer:
# run_engine_GUI()
# else:
# pass
###### END EXAMPLE CODE ######
run()