How do you run a Python script as a service in Windows?

后端 未结 13 1960
你的背包
你的背包 2020-11-22 02:18

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 prov

13条回答
  •  半阙折子戏
    2020-11-22 02:38

    The accepted answer using win32serviceutil works but is complicated and makes debugging and changes harder. It is far easier to use NSSM (the Non-Sucking Service Manager). You write and comfortably debug a normal python program and when it finally works you use NSSM to install it as a service in less than a minute:

    From an elevated (admin) command prompt you run nssm.exe install NameOfYourService and you fill-in these options:

    • path: (the path to python.exe e.g. C:\Python27\Python.exe)
    • Arguments: (the path to your python script, e.g. c:\path\to\program.py)

    By the way, if your program prints useful messages that you want to keep in a log file NSSM can also handle this and a lot more for you.

提交回复
热议问题