@@ -48,13 +48,6 @@ def __exit__(self, exc_type, exc_val, exc_tb):
48
48
del self .printers
49
49
pass
50
50
51
- def thread_connect (self , param_dict ):
52
- client = octorest .OctoRest (
53
- url = "http://" + param_dict ["ip" ]
54
- + ":" + param_dict ["port" ],
55
- apikey = param_dict ["apikey" ])
56
- param_dict ["client" ] = client
57
-
58
51
def connect (self , printer_name ):
59
52
if printer_name == "all" :
60
53
for i_printer in self .printers .keys ():
@@ -65,38 +58,30 @@ def connect(self, printer_name):
65
58
66
59
else :
67
60
print (f"Connecting to { printer_name :10s} ...\t " , end = "" )
68
- logging .info (f"Attempting connection, { printer_name } at { self .printers [printer_name ]['ip' ]} " )
69
-
70
- self .printers [printer_name ]["client" ] = octorest .OctoRest (
71
- url = "http://" + self .printers [printer_name ]["ip" ]
72
- + ":" + self .printers [printer_name ]["port" ],
73
- apikey = self .printers [printer_name ]["apikey" ])
74
- except ConnectionError as e :
75
- # print("This error:")
76
- # print(e)
77
- self .printers [printer_name ]["client" ] = None
78
- else :
79
- arg_return_dict = multiprocessing .Manager ().dict ()
80
- arg_return_dict ['ip' ] = self .printers [printer_name ]['ip' ]
81
- arg_return_dict ['port' ] = self .printers [printer_name ]['port' ]
82
- arg_return_dict ['apikey' ] = self .printers [printer_name ]['apikey' ]
83
- arg_return_dict ['client' ] = self .printers [printer_name ]['client' ]
84
-
85
- # Multiprocessing used so the process can be killed if the printer doesn't connect within a set time
86
- p = multiprocessing .Process (target = thread_connect , args = (arg_return_dict ,))
87
- p .start ()
88
- p .join (OCTOREST_TIMEOUT )
89
-
90
- if p .is_alive ():
91
- logging .info (f"Forced timeout, { printer_name } at { arg_return_dict ['ip' ]} " )
92
- p .terminate ()
93
- p .join ()
94
-
95
- self .printers [printer_name ]['client' ] = arg_return_dict ['client' ]
96
-
97
- if not self .printers [printer_name ]['client' ]:
98
- self .printers [printer_name ]['details' ] = {'state' : "unreachable" }
99
- logging .info (f"Connection failed, { printer_name } at { self .printers [printer_name ]['ip' ]} " )
61
+ logging .info (f"Attempting connection, { printer_name } at { self .printers [printer_name ]['ip' ]} " )
62
+ self .printers [printer_name ]["client" ] = None
63
+
64
+ arg_return_dict = multiprocessing .Manager ().dict ()
65
+ arg_return_dict ['ip' ] = self .printers [printer_name ]['ip' ]
66
+ arg_return_dict ['port' ] = self .printers [printer_name ]['port' ]
67
+ arg_return_dict ['apikey' ] = self .printers [printer_name ]['apikey' ]
68
+ arg_return_dict ['client' ] = None # self.printers[printer_name]['client']
69
+
70
+ # Multiprocessing used so the process can be killed if the printer doesn't connect within a set time
71
+ p = multiprocessing .Process (target = thread_connect , args = (arg_return_dict ,))
72
+ p .start ()
73
+ p .join (OCTOREST_TIMEOUT )
74
+
75
+ if p .is_alive ():
76
+ logging .info (f"Forced timeout, { printer_name } at { arg_return_dict ['ip' ]} " )
77
+ p .terminate ()
78
+ p .join ()
79
+
80
+ self .printers [printer_name ]['client' ] = arg_return_dict ['client' ]
81
+
82
+ if not self .printers [printer_name ]['client' ]:
83
+ self .printers [printer_name ]['details' ] = {'state' : "unreachable" }
84
+ logging .info (f"Connection failed, { printer_name } at { self .printers [printer_name ]['ip' ]} " )
100
85
101
86
try :
102
87
# attempt to get job_info - will except if octopi is disconnected from printer?
0 commit comments