From 63195f93e63cd71a08bccb270f14859d3c5199b2 Mon Sep 17 00:00:00 2001 From: Tom David Mueller Date: Fri, 23 May 2025 15:25:38 +0200 Subject: [PATCH 1/4] remove double rerun --- src/workflow/StreamlitUI.py | 1 + src/workflow/WorkflowManager.py | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/workflow/StreamlitUI.py b/src/workflow/StreamlitUI.py index 58a9b328..60692be4 100644 --- a/src/workflow/StreamlitUI.py +++ b/src/workflow/StreamlitUI.py @@ -1004,6 +1004,7 @@ def execution_section(self, start_workflow_function) -> None: st.rerun() elif c1.button("Start Workflow", type="primary", use_container_width=True): start_workflow_function() + time.sleep(3) st.rerun() log_path = Path(self.workflow_dir, "logs", log_level.replace(" ", "-") + ".log") if log_path.exists(): diff --git a/src/workflow/WorkflowManager.py b/src/workflow/WorkflowManager.py index 426e6eb1..b1a1e682 100644 --- a/src/workflow/WorkflowManager.py +++ b/src/workflow/WorkflowManager.py @@ -40,8 +40,6 @@ def start_workflow(self) -> None: # Add workflow process id to pid dir self.executor.pid_dir.mkdir() Path(self.executor.pid_dir, str(workflow_process.pid)).touch() - time.sleep(3) - st.rerun() def workflow_process(self) -> None: """ From 29bb33da313f407eebe180c3450eddd434e3fc08 Mon Sep 17 00:00:00 2001 From: Tom David Mueller Date: Fri, 23 May 2025 15:28:15 +0200 Subject: [PATCH 2/4] prevent double clicking of start workflow button --- src/workflow/WorkflowManager.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/workflow/WorkflowManager.py b/src/workflow/WorkflowManager.py index b1a1e682..478861b2 100644 --- a/src/workflow/WorkflowManager.py +++ b/src/workflow/WorkflowManager.py @@ -32,6 +32,9 @@ def start_workflow(self) -> None: Starts the workflow process and adds its process id to the pid directory. The workflow itself needs to be a process, otherwise streamlit will wait for everything to finish before updating the UI again. """ + # Catch double presses of the button while app is in frozen state + if self.executor.pid_dir.exists(): return + # Delete the log file if it already exists shutil.rmtree(Path(self.workflow_dir, "logs"), ignore_errors=True) # Start workflow process From 858186532e9fbcdbbb08e5bf6951692b145f5b4b Mon Sep 17 00:00:00 2001 From: Tom David Mueller Date: Fri, 23 May 2025 15:59:07 +0200 Subject: [PATCH 3/4] pep8 --- src/workflow/WorkflowManager.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/workflow/WorkflowManager.py b/src/workflow/WorkflowManager.py index 478861b2..157226de 100644 --- a/src/workflow/WorkflowManager.py +++ b/src/workflow/WorkflowManager.py @@ -33,7 +33,8 @@ def start_workflow(self) -> None: The workflow itself needs to be a process, otherwise streamlit will wait for everything to finish before updating the UI again. """ # Catch double presses of the button while app is in frozen state - if self.executor.pid_dir.exists(): return + if self.executor.pid_dir.exists(): + return # Delete the log file if it already exists shutil.rmtree(Path(self.workflow_dir, "logs"), ignore_errors=True) From ae2e92358ab060a119449a805715bb9dc0ad68db Mon Sep 17 00:00:00 2001 From: Tom David Mueller Date: Sat, 24 May 2025 13:09:22 +0200 Subject: [PATCH 4/4] autorefresh log fragment --- src/workflow/StreamlitUI.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/workflow/StreamlitUI.py b/src/workflow/StreamlitUI.py index 60692be4..892cec82 100644 --- a/src/workflow/StreamlitUI.py +++ b/src/workflow/StreamlitUI.py @@ -989,10 +989,8 @@ def parameter_section(self, custom_parameter_function) -> None: f.write(up.read().decode("utf-8")) streamlit_js_eval(js_expressions="parent.window.location.reload()") - def execution_section(self, start_workflow_function) -> None: - with st.expander("**Summary**"): - st.markdown(self.export_parameters_markdown()) - + @st.fragment(run_every=5) + def show_log(self, start_workflow_function): c1, c2 = st.columns(2) # Select log level, this can be changed at run time or later without re-running the workflow log_level = c1.selectbox( @@ -1029,6 +1027,13 @@ def execution_section(self, start_workflow_function) -> None: st.error("**Errors occurred, check log file.**") st.code(content, language="neon", line_numbers=False) + + def execution_section(self, start_workflow_function) -> None: + with st.expander("**Summary**"): + st.markdown(self.export_parameters_markdown()) + + self.show_log(start_workflow_function) + def results_section(self, custom_results_function) -> None: custom_results_function()