简体   繁体   English

在带有接口的Windows上将python脚本作为服务运行

[英]Run python script as a service on Windows with an interface

I have a problem where I think that I already have a solution. 我有一个问题,我认为我已经有了解决方案。 The only thing I need to know is a bit of knowledge and a rough direction how to do it. 我唯一需要知道的是一些知识和粗略的指导方法。

My problem: A script is running via PyCharm on a server. 我的问题:脚本在服务器上通过PyCharm运行。 When the server is rebooting, because of updates or something similar, I need to restart PyCharm and start the script. 当服务器重新启动时,由于更新或类似的东西,我需要重新启动PyCharm并启动脚本。 I don't get any information that the process has stopped. 我没有获得该过程停止的任何信息。 Moreover without logon via remote desktop and starting PyCharm, the script would not be up again. 此外,如果没有通过远程桌面登录并启动PyCharm,脚本将不会再次启动。

Solution: Start the script as a service and write another script that checks if the process is running. 解决方案:将脚本作为服务启动,并编写另一个脚本来检查进程是否正在运行。

trains of thought My problem is, that by running the script as a service I will loose my IDE (my interface that I have with PyCharm). 列车的认为我的问题是,通过运行脚本作为一个服务,我将失去我的IDE(我的界面,我有PyCharm)。 The way I interact with the script is then moved to my two logging files. 然后我将与脚本交互的方式移动到我的两个日志文件中。 How will I know if the script is still running? 如何知道脚本是否仍在运行? What will happen if an error occurs, that is not handled by my logging setup. 如果发生错误将会发生什么,我的日志记录设置无法处理。 What if an exception raises? 如果例外提出怎么办? Will it be printed to the logfile? 它会被打印到日志文件吗?

It's hard for me to disengage from an interface and do everything in a console. 我很难脱离界面并在控制台中完成所有操作。 I am then dependent on the log files. 然后我依赖于日志文件。 That's pretty new to me. 这对我来说很新鲜。

I think that if I start the script as a service, that it becomes a blackbox. 我认为,如果我将脚本作为服务启动,它就会变成黑盒子。

Notes: I read this guide here , how I can set up a windows service and I set up my logging. 注意:在这里阅读本指南,如何设置Windows服务并设置日志记录。 How can I run my script as a service without loosing information? 如何在不丢失信息的情况下将我的脚本作为服务运行?

Thank you in advance. 先感谢您。

I guess that I already had my answer, when I asked this question. 当我问这个问题时,我想我已经得到了答案。 So without writing a server/client interface, I have to live with my log-files. 因此,如果不编写服务器/客户端接口,我必须使用我的日志文件。 So thank you for your input. 谢谢你的意见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM