Schedules jobs too often if multiple threads are present
- Dominant language
- Python
- Stars
- 12.3k
- Forks
- 999
- PR merge metrics
- No merged PRs in 30d
Description
If I schedule two jobs and each job should be run in one thread, the following minimal example does not work
`import schedule
import threading
import time
from datetime import datetime
def do_task_1() -> None:
print(f"{datetime.now().isoformat()} - task 1 execution - thread {threading.current_thread().name} \n")
def do_task_2() -> None:
print(f"{datetime.now().isoformat()} - task 2 execution - thread {threading.current_thread().name} \n")
def task_1_sheduler() -> None:
schedule.every(10).seconds.do(do_task_1)
while True:
time.sleep(1)
schedule.run_pending()
def task_2_sheduler() -> None:
schedule.every(14).seconds.do(do_task_2)
while True:
time.sleep(1)
schedule.run_pending()
def start_thread_1() -> None:
t = threading.Thread(target=task_1_sheduler)
t.start()
def start_thread_2() -> None:
t = threading.Thread(target=task_2_sheduler)
t.start()
start_thread_1()
start_thread_2()
`
I would expect it to conduct do_task_2 every 14 seconds on thread 2 and do_task_1 independently every 10 seconds on thread 1, but it mixes things up

What am I doing wrong?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by running the minimal two-thread example from the issue and inspect how schedule.every and schedule.run_pending share scheduling state. Check the scheduler API and existing documentation for supported multi-thread behavior. Done means the expected thread-specific execution is reproduced or the supported usage and limitation are clearly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100