Advertisement
homer512

input timeout

Nov 6th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3.  
  4. import select
  5. import sys
  6.  
  7.  
  8. def main():
  9.     print("Question")
  10.     expected = "correct"
  11.     timeout = 10. # seconds
  12.     readready, _, _ = select.select((sys.stdin, ), (), (), timeout)
  13.     if readready:
  14.         answer = input()
  15.         print("Yes" if answer == expected else "No")
  16.     else:
  17.         print("Too late")
  18.  
  19.  
  20. if __name__ == '__main__':
  21.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement