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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  
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
  Cannot run kill -9 through pyvomi on ESXi host nicktx 1 996 Jul-08-2024, 04:07 PM
Last Post: nicktx
  Confused about python execution jpezz 4 2,742 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 5,313 Feb-07-2022, 04:16 PM
Last Post: Gribouillis
  Using a button to kill and restart a script duckredbeard 3 4,760 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,529 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 8,103 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  how to check for thread kill flag nanok66 1 2,964 May-09-2020, 10:06 PM
Last Post: nanok66
  kill thread or process asap, even during time.sleep nanok66 4 4,348 Apr-29-2020, 10:13 AM
Last Post: nanok66
  Python - change variable type during program execution ple 1 3,315 Apr-12-2020, 08:43 AM
Last Post: buran
  Linux: Automatically kill process with fixed exe path anddontyoucomebacknomore 4 4,273 Apr-22-2019, 07:35 AM
Last Post: anddontyoucomebacknomore

Forum Jump:

User Panel Messages

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