I would like to stop a running thread from outside a class, how it's possible
For example I have that broadcasting thread:
class BroadcastThread(Thread):
def __init__(self, converter, websocket_server):
super(BroadcastThread, self).__init__()
self.converter = converter
self.websocket_server = websocket_server
self.bRun = False
def run(self):
try:
while self.bRun:
print(self.bRun)
buf = self.converter.stdout.read1(32768)
if buf:
self.websocket_server.manager.broadcast(buf, binary=True)
elif self.converter.poll() is not None:
break
finally:
self.converter.stdout.close()
and I use it as follows from another class
self.broadcast_thread = BroadcastThread(self.output.converter, websocket_server)
and I need to start and stop it using the following methods
def start_broadcast_stream(self):
self.broadcast_thread.bRun = True
def stop_broadcast_stream(self):
self.broadcast_thread.bRun = False
The variable bRun is not updated at all by using the functions start_broadcast and stop