美文网首页
windows 中,python as service

windows 中,python as service

作者: dc的梦呓 | 来源:发表于2020-05-21 23:05 被阅读0次

windows 系统中,运行python脚本,需打开cmd命令框运行,若在服务器,cmd 命令框很容易被关闭,因此需要安装成window服务来运行。如何用服务运行python脚本,答案就是 nssm(the Non-Sucking Service Manager) 工具。

假设python环境位于 d:\programfiles\miniconda\envs\mypy36_test\,要运行的脚本在当前目录下test.py,
则步骤如下:

  • 安装 python 服务
nssm install mypy36_service   #要安装的服务名

此时弹出nssm的设置框,
Application 切页:
path填入运行的程序,如d:\programfiles\miniconda\envs\mypy36_test\python.exe,
startup directory 填入脚本运行的目录,
Arguments 填入脚本,如 test.py;

I/O切页,填写一些日志项,如:
Input:start
Output:output.log
Error: err.log

然后 install service 即可安装服务成功。

  • 编缉服务
    安装服务完成后,若要修改已安装的服务,可用 edit 命令,如:
nssm edit mypy36_service  #服务名
  • 卸载服务
    若要卸载服务,用remove命令,如:
nssm remove mypy36_service #服务名

相关文章

网友评论

      本文标题:windows 中,python as service

      本文链接:https://www.haomeiwen.com/subject/wzpxahtx.html