Answer the question
In order to leave comments, you need to log in
How to loop the execution of an event every time unit?
Method with
while True:
time.sleep(sec)
event
- Not suitable as it causes the program to hang.
I will describe in more detail: there is a variable >> I want 8 units to be added to this variable every 20 seconds. How can i do this?
Answer the question
In order to leave comments, you need to log in
Of course, I'm not a genius and I don't use the "while" loop, but put Asyncio in there :)
There are two solutions.
1) Use threads
2) Do not "add", and load the code constantly. And only during the call, calculate how much the variable has increased by a simple algorithm.
(time.time() - Time of last data update) // 20 * 8 . By updating the time of the last "update"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question