You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 22.04下修改Streamlit进程名称(setproctitle无效)

解决Streamlit进程名自定义问题

问题原因

使用streamlit run启动应用时,ps看到的进程是Streamlit的CLI主进程,而非你的业务脚本进程。你在脚本中用setproctitle设置的是子进程名称,所以上层主进程仍显示为streamlit,导致设置不生效。

解决方案

方法1:修改脚本直接启动Streamlit服务

修改你的应用脚本,让它直接调用Streamlit的CLI启动逻辑,这样进程名会被正确设置:

修改dashboard1.py:

import streamlit as st
import setproctitle
from streamlit.web import cli as stcli
import sys

# 设置自定义进程名
setproctitle.setproctitle("dashboard_sale")

def main():
    st.title("Streamlit App with Process Title")
    st.write("This is a simple Streamlit app that sets the process title.")

if __name__ == "__main__":
    # 替换命令行参数,直接启动Streamlit服务
    sys.argv = ["streamlit", "run", sys.argv[0]]
    sys.exit(stcli.main())

同理修改dashboard2.py,将进程名设为dashboard_college。

启动命令改为:

nohup python dashboard1.py >data_sale.out 2>&1 &
nohup python dashboard2.py >data_college.out 2>&1 &

方法2:通过exec命令替换进程名(无需修改脚本)

使用bash的exec -a选项直接设置进程的显示名称,无需改动原有脚本:

启动dashboard1.py:

nohup bash -c 'exec -a dashboard_sale python -m streamlit run dashboard1.py' >data_sale.out 2>&1 &

启动dashboard2.py:

nohup bash -c 'exec -a dashboard_college python -m streamlit run dashboard2.py' >data_college.out 2>&1 &

验证结果

执行以下命令查看进程:

ps -e | grep dashboard

此时会显示自定义的进程名dashboard_sale和dashboard_college。

注意事项

  • 避免多个应用输出到同一个日志文件(如原data.out),否则日志会混乱,建议为每个应用单独设置日志文件。

内容的提问来源于stack exchange,提问作者anthoniraj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 11:13:30