I'm running a discord bot, and I want my bot to run a task every hour on the dot.
I tried using tasks.loop(hours=1.0)
, but the period of this loop is terribly inaccurate and gets even worse over time.
How can I solve this problem?
Asked
Active
Viewed 37 times
1

WieeRd
- 792
- 1
- 7
- 17
-
Must this be done inside the code? Because outside of it you can use [task scheduler](https://www.windowscentral.com/how-create-automated-task-using-task-scheduler-windows-10) on windows or a [cron job](https://linuxhint.com/schedule_linux_task/) in linux. – bluevulture May 13 '21 at 11:51
-
2Why was this question closed @PeterWood? It’s not really a duplicate of that... It’s vague, needs details, but I wouldn’t close it as a duplicate. – Łukasz Kwieciński May 13 '21 at 12:14
-
@bluevulture Yes I need it done inside the code, especially inside async function. That duplicate question is not helping me much :( – WieeRd May 13 '21 at 12:23
-
@Ultim8_Clock your task is a bit difficult, as you're using python. In any other language I would suggest a second thread to act as a sort of timer (checking time elapsed in a loop) and then calling an event. – bluevulture May 13 '21 at 12:41
-
@ŁukaszKwieciński can you find a more appropriate duplicate? I'm sure they exist. If OP edits the question, provides better details, and explains why the duplicate doesn't help, I'm sure it can be reopened. – Peter Wood May 13 '21 at 12:58
-
Also, see [ask], how to create a [mcve]. – Peter Wood May 13 '21 at 12:58