Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
30 changes: 25 additions & 5 deletions src/workflow/CommandExecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys
import importlib.util
import json
import streamlit as st

class CommandExecutor:
"""
Expand All @@ -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:
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
9 changes: 5 additions & 4 deletions src/workflow/StreamlitUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)

Expand Down
Loading