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

Why does not the time difference between the two schedules meet expectations? #174

Open
suncle1993 opened this issue Nov 9, 2017 · 0 comments

Comments

@suncle1993
Copy link

when I run the following code, I find the result is confusing me. Can anyone help me?

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

reload(sys)
sys.setdefaultencoding('utf-8')
import time
import datetime
import schedule


def work():
    print 'start: ', datetime.datetime.now()
    time.sleep(15)
    print 'end  : ', datetime.datetime.now()


def main():
    schedule.every(1).minute.do(work)
    while True:
        schedule.run_pending()
        time.sleep(0.01)

main()

The result is as follows:

start:  2017-11-09 14:16:32.320981
end  :  2017-11-09 14:16:47.336356
start:  2017-11-09 14:17:47.340923
end  :  2017-11-09 14:18:02.355287
start:  2017-11-09 14:19:02.361218
end  :  2017-11-09 14:19:17.375502
start:  2017-11-09 14:20:17.377436
end  :  2017-11-09 14:20:32.392757
start:  2017-11-09 14:21:32.401274
end  :  2017-11-09 14:21:47.415794

Why the time difference between two 'start' is not 1 min, but 75s?
Program execution time should be regarded inner time between the scheduling period.
in my viewpoint, the correct time difference is 1 min. the delay caused by time.sleep(15) should not affect.

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

1 participant