I
I
Ilya Lisin2016-01-10 17:31:29
Python
Ilya Lisin, 2016-01-10 17:31:29

Why does the time.sleep command not work for me as it should?

Why, when executing this loop, falling asleep does not occur after update(), as it should, but after executing the next command after sleep?
The code below outputs:
Enter
Update
Enter
and only then goes to sleep.
Update
Input goes to
sleep
etc.

from time import sleep, time

FPS = 1
SEC_PER_FRAME = 1/FPS

def processInput():
    print("Ввод")

def update():
    print("Update")

while True:
    start = time()
    processInput()
    update()
    sleep(start + SEC_PER_FRAME - time())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2016-01-10
@vintello

add print (start + SEC_PER_FRAME - time())
everything at once it will be clear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question