From f7b85fb4ef1b7aadae81130b9303781e5c14efb5 Mon Sep 17 00:00:00 2001 From: AyushStarGupta <37546890+AyushCodez@users.noreply.github.com> Date: Mon, 7 Feb 2022 16:36:20 +0530 Subject: [PATCH] allowing user to exit while running in bg --- main.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index b5f4beb..8a6f7eb 100644 --- a/main.py +++ b/main.py @@ -498,11 +498,11 @@ def change_state(*args): def poll(): - global thread_death + global thread_death, run_in_bg while True: with open("bg_run.txt", 'r') as f: bg_run = int(f.read()) - if thread_death and not(bg_run): + if (thread_death and not(bg_run)) or not(run_in_bg): print("\nShutting down...") break # update graphs with new data @@ -513,6 +513,7 @@ def poll(): thread_death = False +run_in_bg = True def main(): @@ -525,9 +526,17 @@ def main(): disk_graph.animate() def on_closing(): - global thread_death + global thread_death, run_in_bg thread_death = True window.destroy() + with open("bg_run.txt", 'r') as f: + bg_run = int(f.read()) + if bg_run == 1: + nu = input("Press enter to exit") + run_in_bg = False + + + window.protocol("WM_DELETE_WINDOW", on_closing) window.mainloop() except KeyboardInterrupt: