Skip to content

Commit 3f9233d

Browse files
committed
updated app.py
1 parent 89a84d7 commit 3f9233d

File tree

1 file changed

+70
-27
lines changed

1 file changed

+70
-27
lines changed

app.py

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,79 @@
11
import streamlit as st
22
from pathlib import Path
33
import json
4+
import subprocess
5+
import sys
6+
import os
7+
import atexit
8+
import signal
49
# For some reason the windows version only works if this is imported here
510
import pyopenms
611

12+
# Start RQ worker as a background process
13+
def start_rq_worker():
14+
if sys.platform == "win32":
15+
# Windows needs different handling for background processes
16+
worker_process = subprocess.Popen(
17+
["rq", "worker", "--with-scheduler", "-q", "mzml_workflow_run"],
18+
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP
19+
)
20+
else:
21+
# Unix-based systems
22+
worker_process = subprocess.Popen(
23+
["rq", "worker", "--with-scheduler", "-q", "mzml_workflow_run"],
24+
stdout=subprocess.PIPE,
25+
stderr=subprocess.PIPE,
26+
start_new_session=True # This creates a new process group
27+
)
28+
29+
# Register function to terminate worker when app exits
30+
def cleanup():
31+
print("Shutting down RQ worker...")
32+
if sys.platform == "win32":
33+
worker_process.send_signal(signal.CTRL_BREAK_EVENT)
34+
else:
35+
try:
36+
os.killpg(os.getpgid(worker_process.pid), signal.SIGTERM)
37+
except:
38+
worker_process.terminate()
39+
40+
atexit.register(cleanup)
41+
return worker_process
42+
43+
# Initialize settings
744
if "settings" not in st.session_state:
8-
with open("settings.json", "r") as f:
9-
st.session_state.settings = json.load(f)
45+
with open("settings.json", "r") as f:
46+
st.session_state.settings = json.load(f)
47+
48+
# Start RQ worker
49+
print("Starting RQ worker...")
50+
worker_process = start_rq_worker()
51+
print("RQ worker started")
1052

11-
if __name__ == '__main__':
12-
pages = {
13-
str(st.session_state.settings["app-name"]) : [
14-
st.Page(Path("content", "quickstart.py"), title="Quickstart", icon="👋"),
15-
st.Page(Path("content", "documentation.py"), title="Documentation", icon="📖"),
16-
],
17-
"TOPP Workflow Framework": [
18-
st.Page(Path("content", "topp_workflow_file_upload.py"), title="File Upload", icon="📁"),
19-
st.Page(Path("content", "topp_workflow_parameter.py"), title="Configure", icon="⚙️"),
20-
st.Page(Path("content", "topp_workflow_execution.py"), title="Run", icon="🚀"),
21-
st.Page(Path("content", "topp_workflow_results.py"), title="Results", icon="📊"),
22-
],
23-
"pyOpenMS Workflow" : [
24-
st.Page(Path("content", "file_upload.py"), title="File Upload", icon="📂"),
25-
st.Page(Path("content", "raw_data_viewer.py"), title="View MS data", icon="👀"),
26-
st.Page(Path("content", "run_example_workflow.py"), title="Run Workflow", icon="⚙️"),
27-
st.Page(Path("content", "download_section.py"), title="Download Results", icon="⬇️"),
28-
],
29-
"Others Topics": [
30-
st.Page(Path("content", "simple_workflow.py"), title="Simple Workflow", icon="⚙️"),
31-
st.Page(Path("content", "run_subprocess.py"), title="Run Subprocess", icon="🖥️"),
32-
]
33-
}
53+
# Set up page configuration
54+
pages = {
55+
str(st.session_state.settings["app-name"]) : [
56+
st.Page(Path("content", "quickstart.py"), title="Quickstart", icon="👋"),
57+
st.Page(Path("content", "documentation.py"), title="Documentation", icon="📖"),
58+
],
59+
"TOPP Workflow Framework": [
60+
st.Page(Path("content", "topp_workflow_file_upload.py"), title="File Upload", icon="📁"),
61+
st.Page(Path("content", "topp_workflow_parameter.py"), title="Configure", icon="⚙️"),
62+
st.Page(Path("content", "topp_workflow_execution.py"), title="Run", icon="🚀"),
63+
st.Page(Path("content", "topp_workflow_results.py"), title="Results", icon="📊"),
64+
],
65+
"pyOpenMS Workflow" : [
66+
st.Page(Path("content", "file_upload.py"), title="File Upload", icon="📂"),
67+
st.Page(Path("content", "raw_data_viewer.py"), title="View MS data", icon="👀"),
68+
st.Page(Path("content", "run_example_workflow.py"), title="Run Workflow", icon="⚙️"),
69+
st.Page(Path("content", "download_section.py"), title="Download Results", icon="⬇️"),
70+
],
71+
"Others Topics": [
72+
st.Page(Path("content", "simple_workflow.py"), title="Simple Workflow", icon="⚙️"),
73+
st.Page(Path("content", "run_subprocess.py"), title="Run Subprocess", icon="🖥️"),
74+
]
75+
}
3476

35-
pg = st.navigation(pages)
36-
pg.run()
77+
# Run the Streamlit app
78+
pg = st.navigation(pages)
79+
pg.run()

0 commit comments

Comments
 (0)