【问题标题】:windows scheduler not executing my python script - why?windows调度程序不执行我的python脚本-为什么?
【发布时间】:2021-09-10 21:30:41
【问题描述】:

我已经编写了我的第一个脚本,我想每天从我的计算机上的 Windows 调度程序运行它。该脚本用于 1) 确定今天的日出和日落时间,以及 2) 相应地调整笔记本电脑的屏幕亮度。

我知道该脚本有效,因为当我在终端中手动执行它或通过启动批处理文件时,它可以完美运行。但是当我尝试设置我的 Windows 调度程序来触发它时,什么也没有发生。此外,即使我从调度程序窗口单击运行而不是等待其触发时间,它也会说它正在运行但没有任何反应。如果在白天运行,我希望看到屏幕亮度逐渐增加。

亮度.pyw:

# importing the module
import screen_brightness_control as sbc
import datetime
from datetime import timezone
import json
import requests
import sys
from suntime import Sun
import time

send_url = "http://api.ipstack.com/check?access_key=68d6a43e7f37d2152f9bb7dc199b87ef"
geo_req = requests.get(send_url)
geo_json = json.loads(geo_req.text)
latitude = geo_json['latitude']
longitude = geo_json['longitude']

sun = Sun(latitude, longitude)

today_sr = sun.get_sunrise_time()
today_ss = sun.get_sunset_time()

print(today_sr)
print(today_ss)

while True:
    current_time = datetime.datetime.now(timezone.utc)
    if today_ss > current_time > today_sr and sbc.get_brightness() != 100:
        sbc.fade_brightness(100, interval=5)
    elif current_time > today_ss and sbc.get_brightness() != 0:
        sbc.fade_brightness(0, interval=5)
        sys.exit()
    time.sleep(60)

run_brightness_python.bat

"C:\Users\dannl\AppData\Local\Programs\Python\Python39\python.exe" "C:\Users\dannl\scripts\brightness.pyw"
pause

截图:

【问题讨论】:

  • Super User 可能是询问有关使用 Windows 调度程序的更好的地方。

标签: python scheduler


【解决方案1】:

对于发现此问题的任何人,我的问题是我需要选中“仅在用户登录时运行”框。我不知道为什么需要检查它才能工作,但它解决了问题。

【讨论】:

    猜你喜欢
    • 2021-08-30
    • 2010-10-14
    • 2015-04-23
    • 2021-04-29
    • 2013-09-13
    • 2019-05-11
    • 2013-12-10
    • 1970-01-01
    • 2011-11-15
    相关资源
    最近更新 更多