title: python - timed user input
body: <p>Under certain time I need user to input some specific sentence.</p>
  
  <p>For example, user should write below sentence under 10 seconds:</p>
  
  <pre><code>Hello! World.
  </code></pre>
  
  <p>However, if user is unable to finish complete sentence then whatever one wrote should be accepted. So, if one is able to write only <code>Hello! Wo</code> then it should be stored.</p>
  
  <p><strong>Problem</strong> - If user doesn't hit Return/Enter before time then nothing is saved. How to overcome this? Here's my approach -</p>
  
  <pre><code>import time
  from threading import Thread
  
  print('Hello! World')
  user = None
  
  def check():
      time.sleep(10)
      if user != None:
          return
      print ("Too Slow")
  
  Thread(target = check).start()
  
  user = input("Enter above string: \n")
  </code></pre>