From 9f252a486aee75d7e93a2456998b921fb7c6ee62 Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Wed, 30 Apr 2014 15:03:42 +0300 Subject: [PATCH] Fix close while downloading error --- youtube_dl_gui/DownloadThread.py | 9 ++++++--- youtube_dl_gui/YoutubeDLGUI.py | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) 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()