0

I have a thread in my PyGame test code, listening for the pygame.QUIT event. Whenever it detects that event it should quit the whole program. Instead, using exit(0) it only stops the listener thread.

class ListenerThread(threading.Thread):
    def run(self):
        while True:
            print "Listening..."
            events = pygame.event.get()
            for event in events:
                if event.type == pygame.QUIT:
                    exit(0)

            time.sleep(1)

listener = ListenerThread()
listener.setDaemon(True)
listener.start()

The print "Listening..." and time.sleep(1) are there for test purposes only.

I also have some code there for graphics, and whenever I run the program, the terminal just says Listening... repeatedly, then when I click the 'x' button to close the window, the thread stops after the next Listening..., but the graphic stuff still keeps going on, so I have to close the program manually.

So, the question is, how do I close the whole program from within the thread?

Zakru
  • 92
  • 1
  • 11

0 Answers0