I want to know how to kill a QThread. I have to make a game and the 'enemy' moves until it's dead. What I am doing at the moment is to just override the run method with a loop that ends when it dies but with what I have until the moment I can't tell or try if it will work and I would like to know if it works before moving on to the GUI.
So what I have until the moment is the following:
from PyQt5.QtCore import QThread
class Enemy(QThread):
def __init__(self):
super().__init__()
self.alive = True
def run(self):
while self.alive:
# here I code the moving
.
.
.
Outside this, I code if the enemy gets killed I change the attribute alive
of the enemy to False
. So, my question is: do I have to add something after the while breaks (which it will if the enemy dies)? Or do I have to add something like self.terminate()
?
Thank you