我尝试将这两个代码结合起来。我希望它在两个不同的循环中运行。
例如,如果我没有在预定时间写条目,它必须打印"祝你考试好运"。我希望计划任务独立运行。
import schedule
import time
def good_luck():
print("Good Luck for Test")
schedule.every().day.at("00:00").do(good_luck)
while True:
schedule.run_pending()
time.sleep(1)
和
def assistant():
command = input('input: ')
if command == '1':
print('is it one')
else:
print('is not one')
while True:
assistant()
示例输出
Good Luck for Test #automatically at specified times
input: 1
is it one
input: 2
is not one
Good Luck for Test #automatically at specified times
Good Luck for Test #automatically at specified times
Good Luck for Test #automatically at specified times
etc.
多处理 Python 模块可以工作。但是,您可能需要修改输入方法才能获得预期的结果。
import schedule
import time
import multiprocessing
def good_luck():
# schedule.every().day.at("00:00").do(good_luck)
schedule.every(1).minutes.do(_good_luck)
while True:
schedule.run_pending()
time.sleep(1)
def _good_luck():
print("Good Luck for Test")
def assistant():
while True:
command = input('input: ')
if command == '1':
print('is it one')
elif command.lower() == 'quit':
return
else:
print('is not one')
if __name__ == '__main__':
jobs = []
p1 = multiprocessing.Process(target=good_luck)
jobs.append(p1)
p1.start()
assistant()