Skip to content

Commit

Permalink
Merge pull request #26 from riceshowerX/dev
Browse files Browse the repository at this point in the history
修复无法关闭的问题
  • Loading branch information
riceshowerX authored Jun 14, 2024
2 parents 739ada6 + fb98706 commit d71a816
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 1 addition & 7 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@

logging.basicConfig(level=logging.INFO)

# 定义全局变量 is_running
is_running = True

def signal_handler(sig, frame):
logging.info("Stopping SwiftAPI-Connect...")
global is_running
is_running = False # 设置全局变量为 False,通知所有进程停止
exit(0)

def run_process(target, name):
"""运行进程并监控其状态,如果进程退出则尝试重启"""
global is_running
while is_running: # 检查全局变量
while True:
try:
process = Process(target=target)
process.start()
Expand Down
14 changes: 10 additions & 4 deletions ui/main_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from cryptography.fernet import Fernet
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.jobstores.memory import MemoryJobStore
import signal
import os

from ui.components.request_form import get_params
from ui.components.progress_bar import show_progress_bar
Expand Down Expand Up @@ -307,11 +309,15 @@ def run_ui():
st.error(f"请求参数错误: {e}")
except Exception as e:
st.error(f"请求失败: {str(e)}")
# 添加关闭项目按钮
# 添加关闭项目按钮
if st.button("关闭项目"):
# 这里需要设置一个全局变量,用于通知其他进程退出
global is_running
is_running = False
try:
# 获取 run.py 的进程 ID
run_py_pid = os.getppid()
# 向 run.py 进程发送 SIGINT 信号
os.kill(run_py_pid, signal.SIGINT)
except Exception as e:
st.error(f"关闭项目失败: {str(e)}")

if __name__ == "__main__":
run_ui()

0 comments on commit d71a816

Please sign in to comment.