0

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

  • No you don't have to add anything after the `while` is done –  Jun 04 '18 at 19:18
  • Not exactly a duplicate but this might give you an idea https://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread-in-python . In short it is a bad idea to kill a thread in most cases – Bayko Jun 04 '18 at 19:22

0 Answers0