我想在我的项目中使用apscheduler.scheduler
,这是我的代码
import sys
from time import sleep
from apscheduler.scheduler import Scheduler
TOKEN = "****"
sched = Scheduler()
sched.start()
def my_job(text):
print(text)
def main() :
job = sched.add_date_job(my_job('25'), '2017-09-08 14:08:05', args=['text'])
while True:
sleep(1)
sys.stdout.write('.'); sys.stdout.flush()
if __name__ == '__main__':
main()
我得到了这个例外
25
Traceback (most recent call last):
File "F:\+faeze\workspace\testHelloWorld\src\test\testDateTime.py", line 22, in <module>
main()
File "F:\+faeze\workspace\testHelloWorld\src\test\testDateTime.py", line 16, in main
job = sched.add_date_job(my_job('25'), '2017-09-08 14:08:05', args=['text'])
File "C:\Python27\lib\site-packages\apscheduler\scheduler.py", line 318, in add_date_job
return self.add_job(trigger, func, args, kwargs, **options)
File "C:\Python27\lib\site-packages\apscheduler\scheduler.py", line 284, in add_job
options.pop('coalesce', self.coalesce), **options)
File "C:\Python27\lib\site-packages\apscheduler\job.py", line 47, in __init__
raise TypeError('func must be callable')
TypeError: func must be callable
我的错误在哪里?
更新: TypeError: func must be callable
的含义是什么?
答案 0 :(得分:2)
您应修改以下行。
job = sched.add_date_job(my_job, '2017-09-08 14:08:05', ('25',))
这意味着将在指定的时间使用参数25
调用my_job方法