Mar-16-2024, 11:16 AM
Dear,
I want to stop my python program by a bash script normally so i have these code:
So my readUpdate_Thread is kill not my main Thread (while True) .
Thank you for your answers.
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 ) |
Thank you for your answers.