python - 如何让progame只启动一个进程?

标签 python linux pyinstaller

我有一个 python 项目使用 python stand lib socketserver 来监听 tcp 套接字以接收数据。

我使用pyinstaller创建了一个单一的可执行文件,现在我在linux上运行二进制程序,有两个进程。

[root@localhost vmagent]# ./vmagent 10.20.248.37 e93773b6-d04a-40b2-9c57-f4ff6995309b &
[1] 19236
[root@localhost vmagent]# ps -ef|grep vmagent
root     16475 16364  0 14:09 pts/2    00:00:00 tail -30f vmagent.log
root     19236 18581  2 15:21 pts/6    00:00:00 ./vmagent 10.20.248.37 e93773b6-d04a-40b2-9c57-f4ff6995309b
root     19246 19236  8 15:21 pts/6    00:00:00 ./vmagent 10.20.248.37 e93773b6-d04a-40b2-9c57-f4ff6995309b
root     19263 18581  0 15:22 pts/6    00:00:00 grep vmagent
[root@localhost vmagent]# 

退出当前 session 重新登录后,仍然有两个过程。 如何让程序只有一个进程?

[root@localhost ~]# ps -ef|grep vmagent
root     16475 16364  0 14:09 pts/2    00:00:00 tail -30f vmagent.log
root     19236     1  0 15:21 ?        00:00:00 ./vmagent 10.20.248.37 e93773b6-d04a-40b2-9c57-f4ff6995309b
root     19246 19236  0 15:21 ?        00:00:00 ./vmagent 10.20.248.37 e93773b6-d04a-40b2-9c57-f4ff6995309b
root     19542 19505  0 15:34 pts/5    00:00:00 grep vmagent
[root@localhost ~]# 

最佳答案

似乎这就是 pyinstaller 的工作方式。请检查这部分文档https://pythonhosted.org/PyInstaller/advanced-topics.html#the-bootstrap-process-in-detail .

所以你的二进制文件没有启动两次,只是 pyinstaller 使用了两个进程。

关于python - 如何让progame只启动一个进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43407350/

相关文章:

python - 如何使用sklearn HMM计算观测数据的似然度

python - 在后台使用 Selenium

python - 无法安装pyhash模块

linux - 无法使用 Eclipse 在 Windows 上编译 Linux

python - 减少 Pyinstaller 生成的可执行文件的文件大小的一般技巧是什么

python - Celery Django 部署因 Elastic Beanstalk 失败,原因是 ImportError:无法导入名称 'Celery' (ElasticBeanstalk::ExternalInitationError)

linux - netstat -an 和 netstat -na 一样吗?

c - 为什么在 Linux mint 15 中执行 C 程序时会出现错误 "bash: ./a.out: Permission denied"

python - 无法使用 Python 和 Node 共同设计应用程序

python - 有没有办法在使用 pyinstaller 创建 exe 后录制视频