在nssm中运行python脚本

2024-06-02 05:23:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我能够通过非吸吮服务管理器(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)

Tags: fromimport脚本管理器datetimemywindowssleep