Jan-25-2019, 05:00 AM
Import Thread from the threading module and instantiate one.
In essence, you need to setup a race condition such that whichever thread completes first takes precedence. If the Timer completes first, then it calls its function. If the timed input thread completes first, it cancels the Timer altogether.
Where I'm getting stuck conceptually is with the input. User input halts code processing until input is provided. Since it's only valid if the Timer has not completed though, the thread requesting input needs to terminate if the Timer activates. Checking if the Timer has activated requires code to be running though.
from threading import Thread x = Thread(func)The function you pass in will need a parameter for the other thread so it can check the status of it. Frankly, the function will be the tricky part because it needs a time restricted input. To my knowledge, that would require yet another thread to terminate the input thread; that thread would just be a timer. Then again, I wonder if I'm over-complicating it and if there is a more straightforward way to do it.
In essence, you need to setup a race condition such that whichever thread completes first takes precedence. If the Timer completes first, then it calls its function. If the timed input thread completes first, it cancels the Timer altogether.
Where I'm getting stuck conceptually is with the input. User input halts code processing until input is provided. Since it's only valid if the Timer has not completed though, the thread requesting input needs to terminate if the Timer activates. Checking if the Timer has activated requires code to be running though.