M
M
michadimin2021-08-11 18:38:08
Python
michadimin, 2021-08-11 18:38:08

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

2 answer(s)
D
Daniil Kotyashkin, 2021-08-11
@ErVinTract

Of course, I'm not a genius and I don't use the "while" loop, but put Asyncio in there :)

M
MinTnt, 2021-08-11
@MinTnt

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 question

Ask a Question

731 491 924 answers to any question