我有一个 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/