如何在 background/as 进程上 运行 python 编写脚本?

How to run python script on background/as a process?

我想运行一个python脚本作为process/in背景。我搜索并找到了 pythonw.exe,但是当我搜索 pythonw.exe name_of_my_script.py 时什么也没有发生。我是不是做错了什么 and/or 我还能如何 运行 它在后台?

这是我的代码中存在问题的部分:

from selenium import webdriver

我会感谢你的任何帮助。

注: 在这里的评论的帮助下,我了解到 python.exe 运行ning 也不起作用并带来错误 - NameError: name 'PROTOCOL_TLS' is not defined (甚至在正常 运行宁它没有错误。

编辑: 我用了 http://pytoexe.com/ and i got exe file that work but the cmd console still exist ( mabye it because i use phantomjs ? ) click here

我会通过使用 threading 模块来解决这个问题,并使用 os.fork() - 但我不是 运行 Windows。我建议通过 Difference in behavior between os.fork and multiprocessing.Process 查看其他操作系统。

"I want to run a python script as a process/in the background," 是指让 window 不可见吗?如果是这样,只需将脚本保存为 .pyw 而不是 .py

您可以前往 http://pytoexe.com 创建您自己的 exe。 之后转换你的脚本。选择 windows-based 并进行转换。 之后你不会有任何问题。希望有所帮助。