如何在 ubuntu 22.04 中更改 Streamlit 进程名称

问题描述 投票:0回答:1

我的服务器中正在运行两个streamlits应用程序,当应用程序部署在Ubuntu VM服务器中时,我们执行以下命令

$ nohup streamlit run dashboard1.py >data.out 2>&1 &
$ nohup streamlit run dashboard2.py >data.out 2>&1 &

它创建了类似的流程

adminr@micro:~/$ ps -e | grep streamlit
132803 pts/0 00:00:10 streamlit
156959 pts/0 00:00:02 streamlit

我们可以将流程名称从streamlit更改为自定义名称,例如“dashboard_sale”和“dashboard_college”。这将很容易管理和重新部署。

请帮忙

我已经厌倦了 python setproctitle 包,但它不起作用

import streamlit as st
import setproctitle # installed pip install setproctitle

# Set the process title
setproctitle.setproctitle("dashboard_sale")

# Streamlit app content
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__":
    main()

运行此代码所需的包

pip install streamlit setproctitle
linux ubuntu process operating-system streamlit
1个回答
0
投票

这看起来像 有没有办法在 Python 中更改有效进程名称?

简单地说:将所需的命令名称写入 /proc/self/comm 似乎是最简单的。

请注意,此方法更改命令name,而不是命令line。任何报告命令行的内容都不会受到影响,这就是例如的原因。 “ps a”和“ps x”将显示可执行文件的名称,而不是您的自定义名称。

  • “ps -e”的更改将是可见的,您指示这是检查进程名称的方式。
  • “pstree”的更改也将可见
  • 如果您使用“a”、“x”等标志,则“ps”的更改将可见。

据我了解,如果您希望自定义名称作为命令行的一部分可见,则需要创建适当命名的可执行文件。

--克洛德

© www.soinside.com 2019 - 2024. All rights reserved.