【发布时间】:2018-08-06 06:50:40
【问题描述】:
一个多月前,我已将此脚本添加到我的启动应用程序中。每次都能正常工作。
现在,由于某种原因,它不是每次都有效(主要是早上不是每次都有效,现在有不同的变化)。
我已经更改了解释器,缩短了路径 - 它没有帮助。当什么都没有发生时,在输入命令之后(和之前)查找所有工作的 python 进程
ps -fA | grep python
有这个过程。
我使用的是 Linux Mint 18.3 MATE。谢谢。
#! /usr/bin/python3
"""My Alarms."""
import schedule
import time
import webbrowser
import subprocess
def breakfast():
"""Breakfast reminder."""
subprocess.Popen(['notify-send', 'TIME TO EAT BREAKFAST'])
webbrowser.open('/path_to/carbon.ogg')
def dinner():
"""Dinner reminder."""
subprocess.Popen(['notify-send', 'TIME TO MAKE A DINNER'])
webbrowser.open('/path_to/carbon.ogg')
def shut_down():
"""Shut Down (Laptop) reminder."""
subprocess.Popen(['notify-send', 'TIME TO SHUT DOWN THE PC'])
webbrowser.open('/path_to/carbon.ogg')
schedule.every().day.at("07:35").do(breakfast)
schedule.every().day.at("17:10").do(dinner)
schedule.every().day.at("21:00").do(shut_down)
while True:
schedule.run_pending()
time.sleep(1)
【问题讨论】:
-
如果您可以不使用 python 来完成这项工作,因为您仍然在那里运行 bash 命令,请尝试cron。它专为此实用程序而设计。
-
也许我会尝试 cron。但是,为什么首先使用 python 脚本会发生这种情况?困惑。
-
我无法回答。尝试将带有时间戳的内容写入日志文件以帮助调试它。确保以附加模式打开它,例如
open("scriptLog.txt","a") as f: -
我会的。谢谢你所做的一切。
标签: python-3.x python-2.7 schedule linux-mint python-webbrowser