Deadlock when working with jobs inside a job
Hi.
- The following example code schedules two jobs that print "Hello" and "World" every sec.
- The third job should print the status of all scheduled jobs every 5 sec.
- During the first exeution of show_jobstats, a deadlock happens and the job never returns.
import datetime as dt
import time
from scheduler import Scheduler
def do_print(what: str) -> None:
print(what)
def show_jobstats(sched: Scheduler) -> None:
for job in sched.get_jobs():
print("Job stats -> " + str(job))
schedule = Scheduler()
schedule.cyclic(dt.timedelta(seconds=1), do_print, args=("Hello",))
schedule.cyclic(dt.timedelta(seconds=1), do_print, args=("World",))
schedule.cyclic(dt.timedelta(seconds=5), show_jobstats, args=(schedule,))
while True:
schedule.exec_jobs()
time.sleep(1)
Output:
# python3 test.py
Hello
World
Hello
World
Hello
World
Hello
World
Hello
World
^C
Traceback (most recent call last):
Job stats -> CYCLIC, do_print(..), at=2022-12-02 14:27:04, tz=None, in=-0:00:09, #5/inf, w=1
File "//test.py", line 18, in <module>
schedule.exec_jobs()
File "/usr/local/lib/python3.11/site-packages/scheduler/threading/scheduler.py", line 264, in exec_jobs
return self.__exec_jobs(filtered_jobs, ref_dt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/scheduler/threading/scheduler.py", line 205, in __exec_jobs
que.join()
File "/usr/local/lib/python3.11/queue.py", line 90, in join
self.all_tasks_done.wait()
File "/usr/local/lib/python3.11/threading.py", line 320, in wait
waiter.acquire()
KeyboardInterrupt
...