Python Forum
kill thread or process asap, even during time.sleep
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
kill thread or process asap, even during time.sleep
#2
I think you are trying to solve the wrong problem. You shouldn't be looking for a way to stop a thread that may be sleeping, you should look for a way to write your program so it doesn't sleep. This is not only true of machine control and process control programs, but any kind of program that has to react to unpredictable inputs or events (like a user interface for example).

Machine control code should not have any waits. Machine control code should periodically read sensors and make decisions based on the sensor feedback. Maybe you will do this using events (call some function when a button is pressed), or maybe you will have a monitor with a callback (read sensor, if value above some level execute code). If you need to do something for a period of time you record a start time and periodically check if the wait period has expired. Maybe you will have a state machine. The longest your code ever waits for anything should be shorter than the fastest your code has to respond to something.
Reply


Messages In This Thread
RE: kill thread or process asap, even during time.sleep - by deanhystad - Apr-28-2020, 02:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  kill python execution program lebossejames 0 347 Mar-16-2024, 11:16 AM
Last Post: lebossejames
  Use subprocess.Popen and time.sleep chucky831 2 2,069 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,793 Feb-07-2022, 04:16 PM
Last Post: Gribouillis
  Process doesn't work but Thread work ! mr_byte31 4 2,864 Oct-18-2021, 06:29 PM
Last Post: mr_byte31
  Time.sleep: stop appending item to the list if time is early quest 0 1,962 Apr-13-2021, 11:44 AM
Last Post: quest
  Can you end the Time.sleep function boier96 9 10,217 Jan-16-2021, 10:09 PM
Last Post: Serafim
  Code taking too much time to process ErPipex 11 5,278 Nov-16-2020, 09:42 AM
Last Post: DeaD_EyE
  Using a button to kill and restart a script duckredbeard 3 3,507 Sep-01-2020, 12:53 AM
Last Post: duckredbeard
  time.sleep mtnwinds 4 3,046 May-21-2020, 10:12 AM
Last Post: Larz60+
  how to check for thread kill flag nanok66 1 2,283 May-09-2020, 10:06 PM
Last Post: nanok66

Forum Jump:

User Panel Messages

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