Skip to content

Instantly share code, notes, and snippets.

@linzino7
Created December 27, 2017 05:57
Show Gist options
  • Save linzino7/1090b1795e825b8fb4417ccafb5c75e4 to your computer and use it in GitHub Desktop.
Save linzino7/1090b1795e825b8fb4417ccafb5c75e4 to your computer and use it in GitHub Desktop.
Python APScheduler:TypeError: func must be a callable or a textual reference to one . Fix by args.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 26 16:18:35 2017
@author: zino
"""
from datetime import datetime
import time
import os
from apscheduler.schedulers.background import BackgroundScheduler
def tick(name):
print('Tick%s! The time is: %s' % (name,datetime.now()))
if __name__ == '__main__':
scheduler = BackgroundScheduler()
for i in range(1,5):
# 注意要是args 要是 iterable,所以也可以用list丟入。
# 之後add_job 就會把 args帶入tick
scheduler.add_job(tick, 'interval', seconds=i, args=(i,))
scheduler.start()
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
try:
while True:
time.sleep(2)
except (KeyboardInterrupt, SystemExit):
scheduler.shutdown()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment