diff --git a/youtube_dl_gui/DownloadThread.py b/youtube_dl_gui/DownloadThread.py index f28ad18..316fee5 100644 --- a/youtube_dl_gui/DownloadThread.py +++ b/youtube_dl_gui/DownloadThread.py @@ -33,6 +33,7 @@ class DownloadManager(Thread): self.logmanager = logmanager self.options = options self.running = True + self.kill = False self.procList = [] self.procNo = 0 self.start() @@ -69,7 +70,8 @@ class DownloadManager(Thread): sleep(0.1) # If we reach here close down all child threads self.terminate_all() - CallAfter(Publisher.sendMessage, PUBLISHER_TOPIC, DataPack('finish')) + if not self.kill: + CallAfter(Publisher.sendMessage, PUBLISHER_TOPIC, DataPack('finish')) def downloading(self): for proc in self.procList: @@ -98,8 +100,9 @@ class DownloadManager(Thread): if not proc.isAlive(): return proc return None - - def close(self): + + def close(self, kill=False): + self.kill = kill self.procNo = 0 self.running = False CallAfter(Publisher.sendMessage, PUBLISHER_TOPIC, DataPack('close')) diff --git a/youtube_dl_gui/YoutubeDLGUI.py b/youtube_dl_gui/YoutubeDLGUI.py index 0a6bbfe..5895300 100644 --- a/youtube_dl_gui/YoutubeDLGUI.py +++ b/youtube_dl_gui/YoutubeDLGUI.py @@ -288,6 +288,9 @@ class MainFrame(wx.Frame): optionsFrame.Show() def OnClose(self, event): + if self.downloadThread != None: + self.downloadThread.close(kill=True) + self.downloadThread.join() self.save_options() self.Destroy()