【问题标题】:Running python script in nssm在 nssm 中运行 python 脚本
【发布时间】:2019-07-02 01:53:54
【问题描述】:

我能够通过 Non-Sucking Service Manager (nssm) 设置 Windows 服务,以便每 15 分钟运行一次我的 Python 脚本。似乎该服务已创建并正在“运行”,但没有迹象表明该脚本正在运行。当我从命令提示符运行时,脚本和计划运行得很好,所以我知道我的代码没有问题。

我有什么遗漏吗?

import schedule
from time import sleep
from datetime import datetime

def my_func():
    #a bunch of code...
    with open('log.text','a') as outfile:
        outfile.write(f'Program ran at {datetime.now()}')

schedule.every(15).minutes.do(my_func)

while True:
    schedule.run_pending()
    sleep(1)

【问题讨论】:

    标签: python windows windows-services scheduled-tasks nssm


    【解决方案1】:

    你可以在powershell中输入以下内容来查看正在运行哪些服务

    Get-WmiObject win32_service | ?{$_.PathName -like '*nssm*'} | select Name, DisplayName, State, PathName
    

    【讨论】:

      【解决方案2】:

      我遇到了类似的问题。

      我的服务用一个简单的脚本运行得非常顺利,但是更复杂的,它没有运行。 我暂时使用 Windows 任务调度程序来运行我的大脚本,它运行得相当好。

      顺便说一句,我的计时器是(不需要时间表)

      While True:
          Mydef()
          time.sleep(300)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-21
        • 2023-03-29
        • 2018-09-30
        • 2016-06-12
        • 2012-07-29
        • 2016-03-19
        相关资源
        最近更新 更多