Python wait x secs for a key and continue execution if not pressed

前端 未结 4 895
误落风尘
误落风尘 2020-12-09 20:31

I\'m a n00b to python, and I\'m looking a code snippet/sample which performs the following:

  • Display a message like \"Press any key to configure or wait X secon
4条回答
  •  余生分开走
    2020-12-09 21:30

    If you combine time.sleep, threading.Thread, and sys.stdin.read you can easily wait for a specified amount of time for input and then continue.

    t = threading.Thread(target=sys.stdin.read(1) args=(1,))
    t.start()
    time.sleep(5)
    t.join()
    

提交回复
热议问题