I am trying to make a game server which updates after a certain period.
import time
last_time = time.time()
tick = 1
time_since_last_update = 0
while True:
new_time = time.time()
dt = new_time - last_time
time_since_last_update += dt
last_time = new_time
if time_since_last_update > tick:
print("Magic happens")
time_since_last_update = 0
When I do this thing, python consumes 100% computing power on one of the cores. I don't really understand why is this happening and how to fix this if possible.
time.sleep(1)- Montrealtime.sleep(1)is not an option. - Montrealtime.sleep(1), why do you want to something else can you explain? - harshil9968