Python 3 Schedule 随时运行

我目前正在编写一个Python 程序,该程序应该启动多个任务。为了进行时间管理,我安装了 Schedule 库。不幸的是,调度程序每次都会执行我的函数,尽管它没有正确的时间。无论时间是过去还是将来,该函数总是会被执行。


import time

from datetime import date

import schedule



class trader():

  def __init__(self):

      pass


  def scheduler(self, x, y, z):


    

    #schedule.every().monday.at("23:10").tag().do(self.daily(x, y, z))

    schedule.every().day.at("22:10").do(self.daily(x, y, z))


    while True:

        schedule.run_pending()

        time.sleep(1)


  def daily(self, x, y, z):

    

    print("running")


    

    return

感谢您的帮助


慕的地10843
浏览 153回答 1
1回答

繁华开满天机

该Job.do()方法需要一个函数对象,但您正在调用一个函数并将结果传递给.do()def my_job():    # This job will execute every 5 to 10 seconds.    print('Foo')schedule.every(5).to(10).seconds.do(my_job)OP的代码可以更改为schedule.every().day.at("22:10").do(self.daily, x, y, z)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python