title: How to interrupt input after 30 seconds and quit from program? - automatic logout - Python
body: <p>I would like to make automatic logout after 30 seconds. 
  Program waits for user to input something and after 30 seconds I would like program to automatically shut down.
  I have something like this:</p>
  
  <pre><code>import sys, time, os
  
  def start_controller(user):
  
     start = time.time()
     PERIOD_OF_TIME = 30
     os.system('clear')
     print_menu()                            #printing menu
     choice = get_choice()                   #get input from view model
     while choice != "0":
         os.system('clear')
         if choice == "1":
             start += PERIOD_OF_TIME
             print_student_list(Student.student_list,AllAttendance.all_attendance_list)
         if time.time() &gt; start + PERIOD_OF_TIME:
           os.system("clear")
           print('logout')
           Database.save_all_data_to_csv()
           sys.exit()
  </code></pre>