如何在 Windows 中用 Python 创建服务? [英] How to create a service in Python in Windows?

查看:31
本文介绍了如何在 Windows 中用 Python 创建服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现 http://code.activestate.com/recipes/576451-how-to-create-a-windows-service-in-python/

但该服务什么也不做.如何使用该服务运行特定的 Python 文件?

But that service does nothing. How can I use that service for running specific Python file?

推荐答案

您可以将您的业务代码放在 SvcDoRun 中.您链接中的示例每三秒记录一条消息.只是不要忘记定期检查 self.hWaitStop.

You can put your business code in SvcDoRun. The sample at your link just logs a message every three seconds. Just don't forget to check self.hWaitStop periodically.

有时创建一个工作线程并在该线程上完成所有工作很方便,或者启动一个子进程.在这种情况下,另一个复杂因素是您必须考虑同步.

Sometimes it is convenient to create a worker thread and do all work on that thread, or maybe start a child process. An additional complication in this case is that you have to think about synchronization.

这篇关于如何在 Windows 中用 Python 创建服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆