class Thread(threading.Thread): def run(): while True: ........ class Main(): def foo(self): self.thread.start()
Как закрыть поток? self.daemon не подходит т.к поток не закрывает а только передает упровление, и всеравно не работает.
Python 3.*
class Thread(threading.Thread): def run(): while True: ........ class Main(): def foo(self): self.thread.start()
def __init__(self): super(StoppableThread, self).__init__() self._stop_event = threading.Event() def stop(self): self._stop_event.set()
It is generally a bad pattern to kill a thread abruptly, in Python and in any language. Think of the following cases:
the thread is holding a critical resource that must be closed properly
the thread has created several other threads that must be killed as well.
JOHN_16
А чем не устраивает старый добрый способ с флагом в условии цикла?
if flag == True: return 0