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

scheduler does not account for job execution time #268

Closed
bitworm opened this issue Jan 6, 2019 · 4 comments
Closed

scheduler does not account for job execution time #268

bitworm opened this issue Jan 6, 2019 · 4 comments

Comments

@bitworm
Copy link

bitworm commented Jan 6, 2019

It seems that schedule does not account for the time it takes the scheduled job to complete. For example:

import schedule
from datetime import datetime
from time import sleep

def job(seconds):
    print(datetime.now().strftime('%H:%M:%S.%f'))
    sleep(seconds)

schedule.every(10).seconds.do(job, 2)
while True:
    schedule.run_pending()

This code example executes job every 12 seconds instead of every 10. This is not noticeable if jobs are short - but in my case they may take several hours (delay is 1 day), so this is quite problematic.

@MikeDoes
Copy link

MikeDoes commented Jan 8, 2019

This issue has been resolved before:
https://schedule.readthedocs.io/en/stable/faq.html#how-to-execute-jobs-in-parallel

Explanation:
Kindly use the threading library as the docs recommend.

I had the same problem. I told the function to launch every 6 hours so I got a split like so: 6:26, 12:27, 18:28, 0:29,6:30.
This is because it executes the software serially, where as you wish do execute it in parallel. I came from a JS background where functions execute asynchronously, where this issue wouldn't have arised. But of course, the giant upside is the versatility of python.

@dbader
Copy link
Owner

dbader commented Jan 8, 2019

Added an FAQ item, thanks @MikeDoes!

@dbader dbader closed this as completed Jan 8, 2019
@bitworm
Copy link
Author

bitworm commented Jan 8, 2019

@dbader
The code I have written does not require parallel execution - the job takes 2 sec and the delay is 10 seconds. One wouldn't think to look at the parallelization section of the documentation to achieve serially scheduled tasks.

The main problem is the syntax implies a scheduling service (schedule.every(10).seconds.do(job, 2)), but the actual behavior is more like timeout(10).seconds.between.start(job, 2) or something. This is a source of confusion for anyone wanting scheduled jobs. My recommendation is to make the code behavior reflect the actual code syntax.

@bitworm
Copy link
Author

bitworm commented Jan 8, 2019

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

No branches or pull requests

3 participants