Jun-07-2020, 02:39 PM
Thanks for replying :)
Since my last reply i've added multiprocessing and threads so now i'm having some difficulties with your answer because I have a thread running
a process handler that runs the function.
main.py:
Text widget:
Since my last reply i've added multiprocessing and threads so now i'm having some difficulties with your answer because I have a thread running
a process handler that runs the function.
main.py:
Text widget:
def text_widget(self): self.text_window = tk.Text(self, height=100, width=500, bg="gray", wrap=tk.WORD) self.text_window.update() self.text_window.grid(row=7, column=1, rowspan=3, sticky="we") self.text_window.insert(tk.END, ">>>") self.thread_update_text_widget_default() def thread_update_text_widget_default(self): ud = threading.Thread(name="Updating Text Widget from file", target=self.update_text_widget_default, args=()) ud.daemon = False ud.start() def update_text_widget_default(self): print("Updating Text Widget from file") file = fr'c:/users/{os.getlogin()}/Desktop/Gui-Skeleton/default-tmp.txt' with open(file, 'r') as f: console_text = f.readline() for line in console_text: self.text_window.delete('1.0', tk.END) self.text_window.insert(tk.END, f'>>>{line}')
def thread_handler_clr_yes_fn_no(self, host): yn = threading.Thread(target=self.proc_handler_clr_yes_fn_no, args=(host,)) yn.daemon = False yn.start()
def proc_handler_clr_yes_fn_no(self, host): startprocs = [] lastprocs = [] proc1 = mp.Process(name="Clear + No Filename + WriteFile", target=testping.clr_yes_fn_no_writefile, args=(host,)) proc1.daemon = True proc2 = mp.Process(name="Clear + No Filename + PrintOutput", target=testping.clr_yes_fn_no_print_output, args=(host,)) proc3 = mp.Process(name="Clear + No Filename + Generate PrintOutput to GUI", target=testping.clr_yes_fn_no_print_to_gui, args=(host,)) proc4 = mp.Process(name="Remove first line + Write new default file", target=testping.delete_default_lines) startprocs.append(proc1) startprocs.append(proc2) startprocs.append(proc3) lastprocs.append(proc4) for s in startprocs: s.start() for s2 in startprocs: s2.join() for l in lastprocs: l.start()this is on testping.py:
def clr_yes_fn_no_print_to_gui(host, file=sys.stdout): print(f'Current Proccess: {mp.current_process().name} + {mp.current_process().pid}\n') cmd = ["ping", "-n", "4", f'{host}'] proc = sub.Popen(cmd, stdout=sub.PIPE, shell=True, stderr=sub.STDOUT) for stdout_line in proc.stdout: print(stdout_line.decode(), end='', file=file) proc.stdout.close() return_code = proc.wait() if return_code: raise sub.CalledProcessError(return_code, cmd)as for GIT, i'm now using google drive and a local repo but i'll definetly pivot to GIT soon.