简体   繁体   English

类型错误:第一个参数必须在调度程序库中可调用

[英]TypeError: the first argument must be callable in scheduler library

I am getting the following error while running scheduler library.运行调度程序库时出现以下错误。 I did go through similar question and answers but somehow not able to identify the root cuase the error.我确实经历了类似的问题和答案,但不知何故无法确定错误的根源。 Could some help where I am going wrong?可以帮助我出错的地方吗?

TypeError: the first argument must be callable类型错误:第一个参数必须是可调用的

import schedule
    import time


class Scheduler():

    def trigger_testsuite(self):
        print("I am working as expected.")

    def scheule_a_job(self, type="Secs", interval=5):

        if (type == "Mins"):
            schedule.every(interval).minutes.do(self.trigger_testsuite())

        if (type == "Secs"):
            schedule.every(interval).seconds.do(self.trigger_testsuite())

        if (interval == "Hrs"):
            schedule.every().hour.do(self.trigger_testsuite())

        if (interval == "Daily"):
            schedule.every().day.at("10:00").do(self.trigger_testsuite())

        while True:
            schedule.run_pending()
            time.sleep(1)


if __name__ == "__main__":
    run = Scheduler()
    run.scheule_a_job()

TraceBack:-追溯:-

I am working as expected.
Traceback (most recent call last):
  File "foo/Scheduler.py", line 31, in <module>
    run.scheule_a_job()
  File "foo/Scheduler.py", line 16, in scheule_a_job
    schedule.every(interval).seconds.do(self.trigger_testsuite())
  File "foo\Python\Python38-32\lib\site-packages\schedule\__init__.py", line 440, in do
    self.job_func = functools.partial(job_func, *args, **kwargs)
TypeError: the first argument must be callable

Process finished with exit code 1

Do not include the parentheses in the function passed to:不要在传递给的函数中包含括号:

schedule.every(interval).minutes.do()

So, this this line:所以,这一行:

schedule.every(interval).minutes.do(self.trigger_testsuite())

Should be:应该:

schedule.every(interval).minutes.do(self.trigger_testsuite)

And same for all the others.其他人也一样。 Final code becomes:最终代码变为:

import schedule
    import time


class Scheduler():

    def trigger_testsuite(self):
        print("I am working as expected.")

    def scheule_a_job(self, type="Secs", interval=5):

        if (type == "Mins"):
            schedule.every(interval).minutes.do(self.trigger_testsuite)

        if (type == "Secs"):
            schedule.every(interval).seconds.do(self.trigger_testsuite)

        if (interval == "Hrs"):
            schedule.every().hour.do(self.trigger_testsuite)

        if (interval == "Daily"):
            schedule.every().day.at("10:00").do(self.trigger_testsuite)

        while True:
            schedule.run_pending()
            time.sleep(1)


if __name__ == "__main__":
    run = Scheduler()
    run.scheule_a_job()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调度库 TypeError:第一个参数必须是可调用的 - Schedule library TypeError: the first argument must be callable TypeError:第一个参数必须是可调用的 - TypeError: first argument must be callable TypeError:第一个参数必须是可调用的 - TypeError: the first argument must be callable TypeError:当我在django的views.py文件中导入调度程序时,第一个参数必须是可调用的? - TypeError: the first argument must be callable when I import a scheduler in my views.py file of django? TypeError:第一个参数必须是可调用的,defaultdict - TypeError: first argument must be callable, defaultdict 电报TypeError:第一个参数必须可调用 - Telegram TypeError: the first argument must be callable Pandas 造型为 excel “TypeError:第一个参数必须是可调用的” - Pandas styling to excel “TypeError: the first argument must be callable” 第一个参数必须是可调用的或无 - first argument must be callable or None 类型错误:第一个参数必须是可调用的或无 - 错误不是第一次出现而是稍后出现 - TypeError: first argument must be callable or None - error is not coming first time but coming later TypeError:deafultdict必须具有可调用的第一个参数 - TypeError: deafultdict must have first arguments callable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM