如何在 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?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章