后台运行Python脚本不断停止
我制作了一个 .pyw python 脚本,我想在我的计算机后台运行它。
现在,我通过将其放入 Windows 7 计算机的启动文件夹中来将其设置为启动,这应该会在启动时触发它启动。
问题是该脚本似乎由于某种原因在某个时刻停止运行。我认为当我的计算机进入睡眠状态时它就会停止,并且之后不会再次开始运行。
是否有一种“更正确”的方法来运行后台任务,而不会让它在每次计算机进入睡眠状态时死亡?
I made a .pyw python script that I want to have running in the background of my computer.
Right now I have it set to launch by putting it in the Startup folder of my Windows 7 computer, which should trigger it to launch whenever it starts up.
The problem is that the script seems to stop running at some point for some reason. I think it simply stops when my computer goes to sleep and doesn't start running again afterwards.
Is there a "more correct" way to have a background task running that wouldn't have it die every time the computer goes to sleep?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果确实需要持续运行的后台进程,您应该考虑创建一个服务。
pywin32 有助于使用 python 创建 NT 服务
如果您喜欢 .NET,您也可以尝试IronPython,但我不知道这是否更容易。
If there really is need for a continuously running background process, you should look into making a service.
pywin32 helps in creating NT services with python
If you're into .NET, you can try also IronPython, but I don't know whether that is more easy.