dbader / schedule

Python job scheduling for humans.
https://schedule.readthedocs.io/
MIT License
11.71k stars 960 forks source link

Issue with run_pending() in python 3.11: Passing coroutines is forbidden, use tasks explicitly #552

Open FreeCashFlow opened 1 year ago

FreeCashFlow commented 1 year ago

Since upgrading to python 3.11, I had the following exception when run_pending() had a job to run:

Traceback (most recent call last):
   File "C:\Code\Python\blabla\blabla.py", line 23, in run
     await scheduler.run_pending()
   File "C:\Program Files\Python311\Lib\site-packages\aioschedule\__init__.py", line 111, in run_pending
     return await asyncio.wait(jobs, *args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "C:\Program Files\Python311\Lib\asyncio\tasks.py", line 415, in wait
     raise TypeError("Passing coroutines is forbidden, use tasks explicitly.") TypeError: Passing coroutines is forbidden, use tasks explicitly.

I found this note in asyncio documentation: Deprecated since version 3.8, will be removed in version 3.11: Passing coroutine objects to wait() directly is deprecated. https://docs.python.org/3/library/asyncio-task.html#asyncio.wait

So, it seems that:

jobs = [job.run() for job in self.jobs if job.should_run]

should become

jobs = [asyncio.create_task(job.run()) for job in self.jobs if job.should_run]

Thanks