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
  Is there a difference between Python’s time.sleep and win32api.Sleep? phpjunkie 4 1,294 Sep-21-2024, 05:17 PM
Last Post: aakritiintelligence
  Cannot run kill -9 through pyvomi on ESXi host nicktx 1 1,070 Jul-08-2024, 04:07 PM
Last Post: nicktx
  kill python execution program lebossejames 0 860 Mar-16-2024, 11:16 AM
Last Post: lebossejames
  Use subprocess.Popen and time.sleep chucky831 2 3,168 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 5,476 Feb-07-2022, 04:16 PM
Last Post: Gribouillis
  Process doesn't work but Thread work ! mr_byte31 4 4,643 Oct-18-2021, 06:29 PM
Last Post: mr_byte31
  Time.sleep: stop appending item to the list if time is early quest 0 2,460 Apr-13-2021, 11:44 AM
Last Post: quest
  Can you end the Time.sleep function boier96 9 17,913 Jan-16-2021, 10:09 PM
Last Post: Serafim
  Code taking too much time to process ErPipex 11 7,565 Nov-16-2020, 09:42 AM
Last Post: DeaD_EyE
  Using a button to kill and restart a script duckredbeard 3 4,922 Sep-01-2020, 12:53 AM
Last Post: duckredbeard

Forum Jump:

User Panel Messages

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