import schedule
import time
from datetime import datetime
def test_schedule():
import schedule
import time
import threading
from datetime import datetime
def job():
print("job1 start before\t={}".format((datetime.now() - now).seconds))
print("I'm working... in job1 start")
time.sleep(2)
print("I'm working... in job1 end")
print("job1 start after\t={}".format((datetime.now() - now).seconds))
def job2():
print("job2 start before\t={}".format((datetime.now() - now).seconds))
print("I'm working... in job2")
time.sleep(3)
print("job2 start after\t={}".format((datetime.now() - now).seconds))
now = datetime.now()
print("job1 begining\t={}".format((datetime.now() - now).seconds))
schedule.every(5).seconds.do(job)
# print("job2 begining\t={}".format((datetime.now() - now).seconds))
# schedule.every(10).seconds.do(job2)
while True:
# print("start time ={}".format(datetime.now()))
schedule.run_pending()
# time.sleep(6)
if __name__ == '__main__':
test_schedule()
# s1 = datetime.now()
# time.sleep(5)
# s2 = datetime.now() - s1
# print(s2.seconds)
schedule 定时器
最新推荐文章于 2024-04-19 18:11:34 发布