diff --git a/src/common/common.py b/src/common/common.py index 8effd1e5..4d24e765 100644 --- a/src/common/common.py +++ b/src/common/common.py @@ -32,29 +32,6 @@ OS_PLATFORM = sys.platform -def get_max_threads() -> int: - """ - Get max threads for current deployment mode. - - In local mode, checks for UI override in session state. - In online mode, uses the configured value directly. - - Returns: - int: Maximum number of threads to use for parallel processing. - """ - settings = st.session_state.get("settings", {}) - max_threads_config = settings.get("max_threads", {"local": 4, "online": 2}) - - if settings.get("online_deployment", False): - return max_threads_config.get("online", 2) - else: - # Local mode: check for UI override, fallback to config default - return st.session_state.get( - "max_threads_override", - max_threads_config.get("local", 4) - ) - - def is_safe_workspace_name(name: str) -> bool: """ Check if a workspace name is safe (no path traversal characters). diff --git a/src/workflow/CommandExecutor.py b/src/workflow/CommandExecutor.py index 6053e244..86f265b2 100644 --- a/src/workflow/CommandExecutor.py +++ b/src/workflow/CommandExecutor.py @@ -9,6 +9,7 @@ import sys import importlib.util import json +import streamlit as st class CommandExecutor: """ @@ -25,6 +26,28 @@ def __init__(self, workflow_dir: Path, logger: Logger, parameter_manager: Parame self.logger = logger self.parameter_manager = parameter_manager + def _get_max_threads(self) -> int: + """ + Get max threads for current deployment mode. + + In local mode, reads from parameter manager (persisted params.json). + In online mode, uses the configured value directly from settings. + + Returns: + int: Maximum number of threads to use for parallel processing (minimum 1). + """ + settings = st.session_state.get("settings", {}) + max_threads_config = settings.get("max_threads", {"local": 4, "online": 2}) + + if settings.get("online_deployment", False): + value = max_threads_config.get("online", 2) + else: + default = max_threads_config.get("local", 4) + params = self.parameter_manager.get_parameters_from_json() + value = params.get("max_threads", default) + + return max(1, int(value)) + def run_multiple_commands( self, commands: list[str] ) -> bool: @@ -43,10 +66,8 @@ def run_multiple_commands( Returns: bool: True if all commands succeeded, False if any failed. """ - from src.common.common import get_max_threads - # Get thread settings and calculate distribution - max_threads = get_max_threads() + max_threads = self._get_max_threads() num_commands = len(commands) parallel_commands = min(num_commands, max_threads) @@ -234,8 +255,7 @@ def run_topp(self, tool: str, input_output: dict, custom_params: dict = {}) -> b n_processes = max(io_lengths) # Calculate threads per command based on max_threads setting - from src.common.common import get_max_threads - max_threads = get_max_threads() + max_threads = self._get_max_threads() parallel_commands = min(n_processes, max_threads) threads_per_command = max(1, max_threads // parallel_commands) diff --git a/src/workflow/StreamlitUI.py b/src/workflow/StreamlitUI.py index 46fa7d5d..3cca528b 100644 --- a/src/workflow/StreamlitUI.py +++ b/src/workflow/StreamlitUI.py @@ -1112,11 +1112,12 @@ def parameter_section(self, custom_parameter_function) -> None: if not st.session_state.settings.get("online_deployment", False): max_threads_config = st.session_state.settings.get("max_threads", {}) default_threads = max_threads_config.get("local", 4) - st.number_input( - "Threads", + self.input_widget( + key="max_threads", + default=default_threads, + name="Threads", + widget_type="number", min_value=1, - value=default_threads, - key="max_threads_override", help="Maximum threads for parallel processing. Threads are distributed between parallel commands and per-tool thread allocation." )