Python Forum
Can you end the Time.sleep function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can you end the Time.sleep function
#10
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.
Reply


Messages In This Thread
Can you end the Time.sleep function - by boier96 - Jan-16-2021, 03:57 PM
RE: Can you end the Time.sleep function - by Serafim - Jan-16-2021, 10:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  return next item each time a function is executed User3000 19 2,841 Aug-06-2023, 02:29 PM
Last Post: deanhystad
  Use subprocess.Popen and time.sleep chucky831 2 2,072 Aug-11-2022, 07:53 PM
Last Post: carecavoador
  How to immediately kill and restart a thread while using a time.sleep() inside it? philipbergwerf 4 3,812 Feb-07-2022, 04:16 PM
Last Post: Gribouillis
  time function does not work tester_V 4 3,297 Oct-17-2021, 05:48 PM
Last Post: tester_V
  Why recursive function consumes more of processing time than loops? M83Linux 9 4,548 May-20-2021, 01:52 PM
Last Post: DeaD_EyE
  Time.sleep: stop appending item to the list if time is early quest 0 1,963 Apr-13-2021, 11:44 AM
Last Post: quest
  function call at defined system time? Holon 5 3,419 Oct-06-2020, 03:58 PM
Last Post: snippsat
  Having hard time understanding the function self-returning itself twice jagasrik 2 2,652 Aug-15-2020, 08:50 PM
Last Post: deanhystad
  Writing a function to calculate time range in Unix Epoch Time t4keheart 2 3,210 Jul-15-2020, 01:55 AM
Last Post: t4keheart
  time.sleep mtnwinds 4 3,057 May-21-2020, 10:12 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020