Then multiprocessing/threading is the only option since you want to do 2 things at the same time, keep track of the time, and check for button presses. A simple example where the process is terminated after 5 seconds and the list's value is changed to simulate a button press or whatever, which could also return/exit from the function.