Python Forum
kill python execution program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
kill python execution program
#1
Dear,

I want to stop my python program by a bash script normally so i have these code:

 
from time import sleep
import sys
import os
import threading
from _thread import interrupt_main

from timed_count import timed_count

class MyThreadReadUpdate (threading.Thread):
	def __init__(self):
		threading.Thread.__init__(self)
		self._running = True        
		

	def terminate(self):
		self._running = False
        
	def run(self):
		while self._running:

			#print("MyThreadReadUpdate is running")  
			if os.path.exists(sys.argv[2]):                      
				f3 = open(sys.argv[2], "r+")
				valueToDo=f3.readline().rstrip()
				#print(valueToDo+"/")
				if (valueToDo == "Close" ):
					print("Exiting program is asked by user")
					
					sleep(2)
					f3.seek(0);
					f3.write("Nothing")
					f3.close()
					sys.exit(0)

				else:
					#print("run always this program") 
					f3.close()
			#time.sleep(5) 


readUpdate_Thread = MyThreadReadUpdate()
readUpdate_Thread.daemon = True    
readUpdate_Thread.start()


while True:
     print("loop")
     sleep(3)
So my readUpdate_Thread is kill not my main Thread (while True) .

Thank you for your answers.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Confused about python execution jpezz 4 1,390 Oct-09-2022, 06:56 PM
Last Post: Gribouillis
  How to immediately kill and restart a thread while using a time.sleep() inside it? philipbergwerf 4 3,557 Feb-07-2022, 04:16 PM
Last Post: Gribouillis
  Using a button to kill and restart a script duckredbeard 3 3,337 Sep-01-2020, 12:53 AM
Last Post: duckredbeard
  How to to tie the execution of one process to another inside a loop in Python ignorant_wanderer 0 2,057 Jul-11-2020, 03:44 AM
Last Post: ignorant_wanderer
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,939 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  how to check for thread kill flag nanok66 1 2,194 May-09-2020, 10:06 PM
Last Post: nanok66
  kill thread or process asap, even during time.sleep nanok66 4 2,938 Apr-29-2020, 10:13 AM
Last Post: nanok66
  Python - change variable type during program execution ple 1 2,396 Apr-12-2020, 08:43 AM
Last Post: buran
  Linux: Automatically kill process with fixed exe path anddontyoucomebacknomore 4 3,063 Apr-22-2019, 07:35 AM
Last Post: anddontyoucomebacknomore
  How to get memory usage and execution time of each line in python SriRajesh 2 3,138 Mar-07-2019, 12:59 PM
Last Post: SriRajesh

Forum Jump:

User Panel Messages

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