Bonjour
j'ai un thread bloquant qui attend une entrée clavier
comme ceci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class KeyboardThread(threading.Thread):
 
    def __init__(self, input_cbk = None, name='keyboard-input-thread'):
        self.input_cbk = input_cbk
        super(KeyboardThread, self).__init__(name=name)
        self.start()
 
    def kill(self):
        os.kill(self.native_id, signal.SIGKILL)
 
    def run(self):
        cont = True
        while cont:                      
            cont = self.input_cbk(input()) # waits to get input + Return
et j'aimerais savoir si il existe un moyen simple de l'arreter ...
j'ai bien tenté une fonction kill mais la ca arrete tt le monde

je sais qu'en passant par un process a la place on aurait sans doute pas ce problème ...
mais y'a t'il une autre solution en gardant le thread ?

voici mon programme de test
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
import time
import os
import signal
import sys
import threading, multiprocessing
from utils.KeyboardThread import KeyboardThread
 
shutdown = False
 
def keyboradStop(inp):
    if inp == "quit":               
        print('Arret demandé (clavier quit)')
        global shutdown
        shutdown = True
        return True
    else:
        return True
 
#--------------------------------------------------------------------------------
# Main
#--------------------------------------------------------------------------------
if __name__ == '__main__':
    print("--------------------------------------------------------------")
    print(f" Test ") 
    print("--------------------------------------------------------------")
    k = KeyboardThread(keyboradStop)
    while not shutdown:
        time.sleep(1)
    print("--------------------------------------------------------------")    
    #k.kill()
    print("-voila la veritable fin---------------------------------------")
    print("sample")