To go back to beginning,so is
To avoid this use it with
Always run from command line when doing stuff like this or stuff(threading) that an editor/IDE can block.
Example:
msvcrt.getch()
blocking.To avoid this use it with
msvcrt.kbhit()
.Always run from command line when doing stuff like this or stuff(threading) that an editor/IDE can block.
Example:
import time, msvcrt def stop_me(timeout=5): '''None Blocking version''' start_time = time.time() while True: if msvcrt.kbhit(): key = msvcrt.getch() # Python 2 chr(27) if key == chr(27).encode(): print('Esc key pushed') return if time.time() - start_time > timeout: print('Did not manage to stop me in {} sec'.format(timeout)) return stop_me()