Answer the question
In order to leave comments, you need to log in
Moved the Schedule to the second thread, but why doesn't it work?
In general, there are "work" functions:
import threading
from threading import Thread
import time
import schedule
from datetime import datetime
def run_schedule(): # Kerindaily
schedule.every().day.at('10:00').do(everyday)
schedule.every().day.at('10:00').do(everydayphoto)
schedule.every().day.at('21:14').do(everynight)
schedule.every().day.at('21:14').do(everydayphoto)
while True:
schedule.run_pending()
time.sleep(1)
pass
def thread2(): # Поток 2
thr2 = Thread(target=run_schedule)
thr2.start()
pass
if __name__ == '__main__':
thread2()
Answer the question
In order to leave comments, you need to log in
It is not necessary to move the entire function to the second thread. You just need to take out the cycle and you can use schedule everywhere.
import threading
from threading import Thread
import time
import schedule
from datetime import datetime
def everyday():
pass
def everydayphoto():
pass
def everynight():
pass
def everydayphoto():
pass
schedule.every().day.at('10:00').do(everyday)
schedule.every().day.at('10:00').do(everydayphoto)
schedule.every().day.at('21:14').do(everynight)
schedule.every().day.at('21:14').do(everydayphoto)
def sched(num):
while True:
schedule.run_pending()
time.sleep(num)
thr = Thread(target = sched, daemon=True, args = (1,))
thr.start()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question