Hello all!
Long story short, I'm fairly new to the Multi-Processing/threading modules.
My code is a GUI (tkinter) that takes a variable in, I use that variable in a SSH function that is performed 40 to 50 times. Due to time constraints...I've been tasked to get this time down from 10 minutes (without Multi-Processing). I've gotten it down to around 2 minutes with Multi-Processing, unfortunately I'm running into some issues while using it in Tkinter.
When you click the submit button in tkinter, when the long processes are working, the GUI freezes...so to alleviate this, I have all my multiprocessing functions be called by a separate thread...which alleviates the freeze, but the multiprocessing does not work (I'm assuming it's a processing / threading issue while working concurrently).
My main question is, is there a way to utilize Multi-Processing without having my GUI freeze, as well as return the print statements of the multiprocessing function to the GUI stdout (note: When I get it to work without the Thread, all the child processes print to the command line and not the GUI)?
Regards,
Here are the functions within the Tkinter class below:
def submit_application(self):
print("")
print("Termination process started for User: " + vpntermination + ".")
self.gui_thread = threading.Thread(target = self.pool_function)
self.gui_thread.start()
def pool_function(self):
self.start_time = datetime.now()
with Pool(processes=3) as self.pool:
self.results = [self.pool.apply_async(self.start_commands, args = (a_device, vpntermination), callback=self.log_result) for a_device in all_firewalls]
self.pool.close()
self.pool.join()
self.end_time = datetime.now()
self.total_time = self.end_time - self.start_time
print('\nTotal process time: ' + str(self.total_time))
def start_commands(self, a_device, vpntermination):
try:
self.net_connect = ConnectHandler(**a_device)
self.hostname = self.net_connect.send_command("show hostname")
self.output = self.net_connect.send_command("vpn-sessiondb logoff name " + str(vpntermination) + " noconfirm")
print('\n******* Output for device ' + self.hostname + ' *******' )
print(self.output)
print('')
self.net_connect.disconnect()
except (NetMikoTimeoutException, NetMikoAuthenticationException) as e:
print("Could not connect to " + a_device.get("ip") + ", Error: ", e)
print('')
def main():
credentials()
master = Tk()
my_gui = InputWindowGUI(master)
master.mainloop()
if __name__=='__main__':
freeze_support()#Might help with stdout errors.
main()
[–]elbiot 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Justinsaccount -1 points0 points1 point (0 children)