Can I run a Python script as a service?

前端 未结 6 950
旧巷少年郎
旧巷少年郎 2020-12-01 10:05

Is it possible to run a Python script as a background service on a webserver? I want to do this for socket communication.

6条回答
  •  甜味超标
    2020-12-01 10:09

    on XP and later you can use the sc.exe program to use any .exe as service:

    >sc create
    Creates a service entry in the registry and Service Database.
    SYNTAX:
    sc create [service name] [binPath= ]  ...
    CREATE OPTIONS:
    NOTE: The option name includes the equal sign.
     type= 
           (default = own)
     start= 
           (default = demand)
     error= 
           (default = normal)
     binPath= 
     group= 
     tag= 
     depend= 
     obj= 
           (default = LocalSystem)
     DisplayName= 
     password= 
    

    You can start your pythonscript by starting the python interpreter with your script as argument:

    python.exe myscript.py
    

提交回复
热议问题