Browse Source

Attempt to enable canceling when postprocess is triggered

Not yet working. A multi-threading approach,
where the process triggering gets its own thread
could be the solution.
experiments/remove-exchange-grid
Sven Karsten 7 months ago
parent
commit
f84bcff15f
  1. 11
      gui/iow_esm_functions.py
  2. 6
      gui/postprocess_window.py

11
gui/iow_esm_functions.py

@ -27,6 +27,7 @@ class IowEsmFunctions:
self.shell_cmd_thread = Thread()
self.cancel_cmd = Event()
self.cmd_finished = Event()
self.output = ""
def start_execute_shell_cmd(self, cmd, printing, stop_event):
@ -46,13 +47,21 @@ class IowEsmFunctions:
os.killpg(os.getpgid(p.pid), signal.SIGTERM)
self.gui.print("...canceled")
stop_event.clear()
self.mark_cmd_finished()
return
if printing:
self.gui.print("...done")
self.output = str(p.stdout.read().decode("utf-8"))
self.mark_cmd_finished()
return
def mark_cmd_finished(self):
self.cmd_finished.set()
self.cmd_finished.clear()
def execute_shell_cmd(self, cmd, printing = True, blocking = True):
@ -61,6 +70,7 @@ class IowEsmFunctions:
if blocking:
self.start_execute_shell_cmd(cmd, printing, self.cancel_cmd)
self.mark_cmd_finished()
return self.output
if self.shell_cmd_thread.is_alive():
@ -78,6 +88,7 @@ class IowEsmFunctions:
self.gui.print("Warning: No command is running.")
return
self.gui.print("Canceling...")
self.cancel_cmd.set()
def clone_origins(self):

6
gui/postprocess_window.py

@ -8,6 +8,7 @@ from iow_esm_globals import *
from iow_esm_buttons_and_labels import *
from check_dependencies import get_dependency_ordered_groups
import tkinter.ttk as ttk
import time
class PostprocessWindow():
@ -255,7 +256,10 @@ class PostprocessWindow():
if self.current_from_dates[model] != "" and self.current_to_dates[model] != "":
cmd += " " + self.current_from_dates[model] + " " + self.current_to_dates[model]
self.master.functions.execute_shell_cmd(cmd, blocking = False)
self.master.functions.execute_shell_cmd(cmd, blocking = True)
#while not self.master.functions.cmd_finished.wait():
# self.master.window.update_idletasks()
return True

Loading…
Cancel
Save