Apscheduler as a class member
See original GitHub issueHi,
I’m trying to create a simple class with apscheduler
with specific jobstore suppose this simple example:
from datetime import datetime
from time import sleep
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
class sched:
def __init__(self):
jobstores = {
'default': SQLAlchemyJobStore(url='sqlite:///test.db')
}
self.scheduler = BackgroundScheduler(jobstores=jobstores)
job2 = self.scheduler.add_job(self.tick, 'interval', args=[1, 2], kwargs=dict(a=2,b=3), seconds=5, replace_existing=True)
self.scheduler.start()
def tick(self, i, j, **kwargs):
print("hello{} {}".format(i, j))
for k in kwargs:
print(k, ":", kwargs[k])
if __name__ == '__main__':
#print(scheduler.get_jobs())
schedule = sched()
while True:
sleep(1)
but it gaves me this error:
TypeError: tick2() missing 1 required positional argument: ‘j’
but when I change the instance name with this it works fine:
if __name__ == '__main__':
#print(scheduler.get_jobs())
sched = sched()
while True:
sleep(1)
It works fine. I don’t have any problem with default jobstore
. I don’t know if the problem relates to apscheduler
or not but I’m a little confused here why should I use an instance name with the exact name of the class name.
Thanks.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
apscheduler - import a class method from file as static in python
I'm trying to use the Apscheduler library. I created a class method for the library and added some missing features by myself as...
Read more >User guide — APScheduler 3.9.1 documentation
APScheduler provides many different ways to configure the scheduler. You can use a configuration dictionary or you can pass in the options as...
Read more >apscheduler.job — APScheduler 3.9.1 documentation
Contains the options given when scheduling callables and its current schedule and other state. This class should never be instantiated by the user....
Read more >apscheduler.events - Read the Docs
An event that concerns the submission of a job to its executor. Variables. scheduled_run_times – a list of datetimes when the job was...
Read more >Frequently Asked Questions — APScheduler 3.9.1 ...
from apscheduler.schedulers.background import BackgroundScheduler def ... to the module level or to class level as either a class method or a static method....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What is a “schedule class” here? I can give advice if you show me some code but I am not some free consultancy service.
Not to mention that starting the scheduler directly in
__init__()
is also a bad idea, particularly from the testability standpoint.