简体   繁体   中英

python- TypeError: func must be callable

I want to use apscheduler.scheduler in my project and this is my code

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()

and I got this exception

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

where is my mistake??

update: what does TypeError: func must be callable mean?

You should modify the following line.

job = sched.add_date_job(my_job, '2017-09-08 14:08:05', ('25',))

This means my_job method will be called at the specified time with argument 25

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM