title: Adding a timeout to a python subprocess
body: <p>I have been trying to add a timeout to my python subprocess but as yet I cannot get it to work. I have a menu.py which when a button is pressed runs: subprocess.call(['python3', 'travel.py'])</p>
  <p>That code is below, the trouble is the code never seems to hit the break. The aim is that if there's no activity after 15 seconds the code breaks and goes back to menu.py. Alternately I did successfully add a timeout to the subprocess.call but that then kills menu.py as well.</p>
  <pre><code>delay=15
  close_time=time.time()+delay
  
  try:
    while True:
      if time.time()&gt;close_time:
        break
      lcd.clear()
      time.sleep(1)
      lcd.message('Scan Fob to\nClock in or out')
      id, text = reader.read()
  
      cursor.execute(&quot;Select uid, name, status, current_location  FROM users WHERE rfid_uid=&quot;+str(id))
      result = cursor.fetchone()
  
      lcd.clear()
      
      if cursor.rowcount &gt;= 1: #If scanned fob comes back with a match in the users table
        if result[2] == 1: #Checks if the status of the user is in (1)
          if result[3] == 997: #Checks if the location is travelling (997)
            beepIn()
            lcd.message(result[1] + &quot;\nHas Returned!&quot;)
            cursor.execute(&quot;INSERT INTO attendance (user_id, status, terminal_id_in) VALUES (%s, %s, %s)&quot;, (result[0],&quot;1&quot;, tid) )
            cursor.execute(&quot;UPDATE users SET status = 1, current_location = 1 WHERE rfid_uid =&quot;+str(id))  
          else: #User is not currently travelling so must be set as travelling using location 997
            lcd.message(result[1] + &quot;\nNow Travelling&quot;)
            beepOut()
            #cursor.execute(&quot;&quot;&quot;UPDATE attendance SET clock_out = now(), terminal_id_out = '%s' WHERE DATE(clock_in) = CURDATE() AND user_id ='%s' ORDER BY attend_id DESC LIMIT 1&quot;&quot;&quot;, (tid, result[0]))
            cursor.execute(&quot;UPDATE users SET status = 0, current_location = 997 WHERE rfid_uid =&quot;+str(id)) #Changes status to Out and Location to Clocked Out
          connection.commit()
        else: #The user isn't clocked in at this point so shouldn't be trying to travel - probably hit the wrong button
          lcd.message(&quot;Error: User&quot; + &quot;\nClocked Out&quot;) #Tells the user they are clocked out
          beepBanned()
          time.sleep(5)
          exit() #Quits the sub process and exits back to the main menu
      else: #This will fire if EITHER there is no fob in users table matching it OR weirdly the same fob is assigned to more than one user which means yu have done a bad job in validation.
        beepBanned()
        lcd.message(&quot;Fob Invalid \nPls return to HR&quot;)
        cursor.execute(&quot;INSERT INTO blockedfobs (fob_id, terminal_id) VALUES (%s, %s)&quot;, (id, tid) )
      connection.commit()
      time.sleep(4)
  finally:
    GPIO.cleanup()
  </code></pre>