Bonjour,
Je lance mon script python via un bash script sous linux, mais je souhaiterais lorsque je souhaite stopper son exécution, par conséquent je passe par un fichier auquel j'écris le mot Close pour arrêter le programme script.py mais je constate que cela stop uniquement le Thread et non le Thread principal (While True)malgré le sys.exit(0).
Sauriez-vous me dire comment procéder svp?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 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)
Merci d'avance.