如何在 Windows 中将 Python 脚本作为服务运行? - How do you run a Python script as a service in Windows?

问题:

I am sketching the architecture for a set of programs that share various interrelated objects stored in a database.我正在为一组共享存储在数据库中的各种相互关联对象的程序绘制架构。 I want one of the programs to act as a service which provides a higher level interface for operations on these objects, and the other programs to access the objects through that service.我希望其中一个程序充当服务,为对这些对象的操作提供更高级别的接口,而其他程序通过该服务访问这些对象。

I am currently aiming for Python and the Django framework as the technologies to implement that service with.我目前的目标是将 Python 和 Django 框架作为实现该服务的技术。 I'm pretty sure I figure how to daemonize the Python program in Linux.我很确定我知道如何在 Linux 中守护 Python 程序。 However, it is an optional spec item that the system should support Windows.但是,系统应该支持 Windows 是一个可选的规范项。 I have little experience with Windows programming and no experience at all with Windows services.我对 Windows 编程几乎没有经验,对 Windows 服务也没有任何经验。

Is it possible to run a Python programs as a Windows service (ie run it automatically without user login)?是否可以将 Python 程序作为 Windows 服务运行(即无需用户登录即可自动运行)? I won't necessarily have to implement this part, but I need a rough idea how it would be done in order to decide whether to design along these lines.我不一定要实现这部分,但我需要一个粗略的想法,以便决定是否按照这些方式进行设计。

Edit: Thanks for all the answers so far, they are quite comprehensive.编辑:感谢到目前为止的所有答案,它们非常全面。 I would like to know one more thing: How is Windows aware of my service?我还想知道一件事: Windows 如何知道我的服务? Can I manage it with the native Windows utilities?我可以使用本机 Windows 实用程序管理它吗? What is the equivalent of putting a start/stop script in /etc/init.d?在 /etc/init.d 中放置启动/停止脚本的等价物是什么?


解决方案:

参考一: https://stackoom.com/question/8Qe
参考二: How do you run a Python script as a service in Windows?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章