Skip to content

Instantly share code, notes, and snippets.

@linzino7
Created December 27, 2017 05:59
Show Gist options
  • Save linzino7/417a4221eac8310aca8f0e34102d6ceb to your computer and use it in GitHub Desktop.
Save linzino7/417a4221eac8310aca8f0e34102d6ceb 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 __cell__.
#!/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
class Foo:
def __init__(self,n):
self.name=n
def __call__(self):
self.tk(self.name)
def tk(self,name):
print('Tick%s! The time is: %s' % (name,datetime.now()))
if __name__ == '__main__':
scheduler = BackgroundScheduler()
for i in range(1,5):
scheduler.add_job(Foo(i), 'interval', seconds=i)
scheduler.start()
try:
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