Created
December 27, 2017 05:53
-
-
Save linzino7/29e917466b24a7abdeb0564deff8b255 to your computer and use it in GitHub Desktop.
Python APScheduler:TypeError: func must be a callable or a textual reference to one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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): | |
#直接帶入參數會遇到錯誤訊息 | |
#TypeError: func must be a callable or a textual reference to one | |
scheduler.add_job(tick(i), 'interval', seconds=i) | |
scheduler.start() | |
try: | |
# This is here to simulate application activity (which keeps the main thread alive). | |
while True: | |
time.sleep(2) | |
except (KeyboardInterrupt, SystemExit): | |
print('exit') | |
scheduler.shutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment