Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition when adding a job once scheduler is started #13

Closed
agronholm opened this issue Jun 20, 2011 · 3 comments
Closed

Race condition when adding a job once scheduler is started #13

agronholm opened this issue Jun 20, 2011 · 3 comments

Comments

@agronholm
Copy link
Owner

Originally reported by: chemicalstorm (Bitbucket: chemicalstorm, GitHub: chemicalstorm)


Using the following code:

#!python
from apscheduler.scheduler import Scheduler
logging.basicConfig(level=logging.DEBUG)

def job_function():
    print "Hello World"
    time.sleep(10)

# Start the scheduler
sched = Scheduler()

sched.start()
sched.add_cron_job(job_function, **{'minute':'*/2'})

It seems we can fall in a race condition. Several launches of this code display different outputs (I just added a log trace in scheduler.py, function //_real_add_job//)

Functionnal:

guestdev@guestdev-laptop:~/Projet/bac_a_sable/APScheduler-2.0.1$ python test_aps.py 
INFO:apscheduler.threadpool:Started thread pool with 0 core threads and 20 maximum threads
INFO:apscheduler.scheduler:Scheduler started
DEBUG:apscheduler.scheduler:Looking for jobs to run
DEBUG:apscheduler.scheduler:No jobs; waiting until a job is added
DEBUG:apscheduler.scheduler:Adding real job with wakeup: True
INFO:apscheduler.scheduler:Added job "job_function (trigger: cron[minute='*/2'], next run at: 2011-06-20 13:32:00)" to job store "default"
DEBUG:apscheduler.scheduler:Looking for jobs to run
DEBUG:apscheduler.scheduler:Next wakeup is due at 2011-06-20 13:32:00 (in 100.794154 seconds)

Race condition, which leads to multiple fires of the same job:

guestdev@guestdev-laptop:~/Projet/bac_a_sable/APScheduler-2.0.1$ python test_aps.py 
INFO:apscheduler.threadpool:Started thread pool with 0 core threads and 20 maximum threads
INFO:apscheduler.scheduler:Scheduler started
DEBUG:apscheduler.scheduler:Adding real job with wakeup: True
DEBUG:apscheduler.scheduler:Looking for jobs to run
INFO:apscheduler.scheduler:Added job "job_function (trigger: cron[minute='*/2'], next run at: 2011-06-20 13:32:00)" to job store "default"
DEBUG:apscheduler.scheduler:Next wakeup is due at 2011-06-20 13:32:00 (in 99.725313 seconds)
DEBUG:apscheduler.scheduler:Looking for jobs to run
DEBUG:apscheduler.scheduler:Next wakeup is due at 2011-06-20 13:32:00 (in 99.724925 seconds)

I can't reproduce the bug if I add a job before starting the scheduler.


@agronholm
Copy link
Owner Author

Original comment by Alex Grönholm (Bitbucket: agronholm, GitHub: agronholm):


This output does not actually demonstrate multiple fires of the same job.
Can you reproduce that? The scheduler waking up more than once is a non-issue.

@agronholm
Copy link
Owner Author

Original comment by chemicalstorm (Bitbucket: chemicalstorm, GitHub: chemicalstorm):


Nervermind, I am such a dumbass...
I was mislead by the scheduler waking up twice in my example, that I did not see I messed up my cronjob (not the one attached as example in my first post):

#!python
sched.add_cron_job(job_function, **{'minute':'*/2', 'second':'*'})

properly triggers the job every second....

Anyway, thanks for your excellent work on this module! It really awesome and useful.

@agronholm
Copy link
Owner Author

Original comment by Alex Grönholm (Bitbucket: agronholm, GitHub: agronholm):


Btw, you have a very peculiar way of doing sched.add_cron_job(job_function, minute='/2', second='')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant