Why does the code not work?
time.sleep
returns nothing; the value of the time.sleep(..)
become None
; while
loop body is not executed.
How to solve it
If you're on Unix, you can use select.select
.
import select
import sys
print('Press enter to continue.', end='', flush=True)
r, w, x = select.select([sys.stdin], [], [], 600)
Otherwise, you should use thread.
Windows specific solution that use msvcrt
:
import msvcrt
import time
t0 = time.time()
while time.time() - t0 < 600:
if msvcrt.kbhit():
if msvcrt.getch() == '\r': # not '\n'
break
time.sleep(0.1)