Jan-16-2021, 10:09 PM
Before Python 3.5 it was actually possible to "wake up" a time.sleep by sending some interrupt signal to the running program but from python 3.5 and up this is no longer possible. The only possibility is to send an interrupt signal that generates an exception. You will have to know how to generate interrupt signals and how to make these signal handlers cause an exception. Never tried it myself but I can imagine that you can make some keyboard combination generate an interrupt signal which you handle by a custom signal handler that triggers an exception.
I also think it is an interesting problem as some signals, like ctrl-c, are meant to immediately interrupt a running program. Most GUI programs have some kind of loop to handle events and if you press ctrl-c it may take a considerable time before the program reacts, if it does at all react.
But in the comments to time.sleep it is (or was a the time I read it, it might have changed again) explicitly stated that time.sleep(n) will sleep for at least n seconds even if there is an interrupt signal unless the signal causes an exception.
I also think it is an interesting problem as some signals, like ctrl-c, are meant to immediately interrupt a running program. Most GUI programs have some kind of loop to handle events and if you press ctrl-c it may take a considerable time before the program reacts, if it does at all react.
But in the comments to time.sleep it is (or was a the time I read it, it might have changed again) explicitly stated that time.sleep(n) will sleep for at least n seconds even if there is an interrupt signal unless the signal causes an exception.