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

When change the os's time, the apcheduler can't work well #752

Closed
3 tasks done
sangensong opened this issue Jul 11, 2023 · 4 comments
Closed
3 tasks done

When change the os's time, the apcheduler can't work well #752

sangensong opened this issue Jul 11, 2023 · 4 comments
Labels

Comments

@sangensong
Copy link

Things to check first

  • I have checked that my issue does not already have a solution in the FAQ

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

Version

3.10.1

What happened?

first, I run the python file
second, when I run the cmd below on linux

date -s 20220711

the task will not run forever

How can we reproduce the bug?

import datetime
from apscheduler.executors.pool import ThreadPoolExecutor

from apscheduler.schedulers.blocking import BlockingScheduler


def hello():
    print('hello', datetime.datetime.now())


def world():
    print("world", datetime.datetime.now())


def hello_world():
    print("hello_world", datetime.datetime.now())


max_thread_num = 20
tasks = [
    {
        'func': hello,
        'trigger': 'interval',
        'seconds': 1,
        'coalesce': False
    },
    {
        'func': world,
        'trigger': 'interval',
        'seconds': 2,
        'coalesce': False
    },
    {
        'func': hello_world,
        'trigger': 'interval',
        'seconds': 3,
        'coalesce': False
    },

]
executors = {
    'default': ThreadPoolExecutor(max(max_thread_num, len(tasks)))
}
task_start_interval = 1
scheduler = BlockingScheduler(executors=executors)
next_run_time = datetime.datetime.now()
for task in tasks:
    next_run_time += datetime.timedelta(seconds=task_start_interval)
    task['next_run_time'] = next_run_time
    scheduler.add_job(**task)
scheduler.start()
@sangensong sangensong added the bug label Jul 11, 2023
@agronholm
Copy link
Owner

agronholm commented Aug 12, 2023

How would the scheduler get notified of system clock changes?

@sangensong
Copy link
Author

I think below code might have design error. It's impossible to notify event when self._event.wait(wait_seconds) will wait too long time

    def _main_loop(self):
        wait_seconds = TIMEOUT_MAX
        while self.state != STATE_STOPPED:
            self._event.wait(wait_seconds)
            self._event.clear()
            wait_seconds = self._process_jobs()

@agronholm
Copy link
Owner

Can you explain? This code is waiting for any notification for wait_seconds, and proceeds to process the jobs if there is no notification within that time.

@agronholm
Copy link
Owner

I've opened #794 as a feature request. That should cover this case if I understood correctly.

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

No branches or pull requests

2 participants