diff --git a/gameview.py b/gameview.py index 457f6c1..019addc 100644 --- a/gameview.py +++ b/gameview.py @@ -3076,7 +3076,8 @@ class gui(QtGui.QWidget): self.stream = None if self.download_thread: - self.download_thread.terminate() # Live dangerously + self.download_thread.stop() + self.download_thread.wait() self.download_thread = None def playDownloadedMusic(self, file_length): @@ -3751,11 +3752,16 @@ class music_download_thread(QtCore.QThread): super(music_download_thread, self).__init__() self.caller = caller self.url = url + self.exiting = False def run(self): + self.exiting = False self.download(self.url) def download(self, url): + if self.exiting: + return + headers = { 'User-Agent': "AO2XP %s" % (GAME_VERSION), 'Accept': '*/*', @@ -3779,11 +3785,19 @@ class music_download_thread(QtCore.QThread): buffer_size = 8192 while bytes_downloaded < file_length: + if self.exiting: + self.quit() + break + chunk = response.read(buffer_size) if not chunk: break + stream += chunk bytes_downloaded += len(chunk) - + self.caller.stream = create_string_buffer(stream) - self.finished_signal.emit(file_length) \ No newline at end of file + self.finished_signal.emit(file_length) + + def stop(self): + self.exiting = True \ No newline at end of file