Skip to content

Commit

Permalink
Handle errors in the callback function
Browse files Browse the repository at this point in the history
  • Loading branch information
Javinator9889 committed Feb 12, 2020
1 parent de4e07f commit 5fd2844
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
13 changes: 9 additions & 4 deletions YouTubeMDBot/tests/downloader.py
Expand Up @@ -22,10 +22,10 @@ def test_multithread_download(self):
url="https://www.youtube.com/watch?v=9HfoNUjw5u8")

ytdl = MultipleYouTubeDownloader()
ft1 = ytdl.download_async(yt1)
ft2 = ytdl.download_async(yt2)
ft3 = ytdl.download_async(yt3)
ft4 = ytdl.download_async(yt4)
ft1 = ytdl.download_async(yt1, error_callback=handle_error)
ft2 = ytdl.download_async(yt2, error_callback=handle_error)
ft3 = ytdl.download_async(yt3, error_callback=handle_error)
ft4 = ytdl.download_async(yt4, error_callback=handle_error)

t1 = threading.Thread(target=self.write_to_file, args=(ft1, "v1.m4a",))
t2 = threading.Thread(target=self.write_to_file, args=(ft2, "v2.m4a",))
Expand Down Expand Up @@ -56,5 +56,10 @@ def write_to_file(self, future, name: str):
self.barrier()


def handle_error(exception):
print("Unexpected exception: " + str(exception))
raise exception()


if __name__ == '__main__':
unittest.main()
16 changes: 10 additions & 6 deletions YouTubeMDBot/tests/identifier.py
Expand Up @@ -53,12 +53,12 @@ def test_multiple_download_identification(self):

ytdl = MultipleYouTubeDownloader()

f1 = ytdl.download_async(yt1)
f2 = ytdl.download_async(yt2)
f3 = ytdl.download_async(yt3)
f4 = ytdl.download_async(yt4)
f5 = ytdl.download_async(yt5)
f6 = ytdl.download_async(yt6)
f1 = ytdl.download_async(yt1, error_callback=handle_error)
f2 = ytdl.download_async(yt2, error_callback=handle_error)
f3 = ytdl.download_async(yt3, error_callback=handle_error)
f4 = ytdl.download_async(yt4, error_callback=handle_error)
f5 = ytdl.download_async(yt5, error_callback=handle_error)
f6 = ytdl.download_async(yt6, error_callback=handle_error)

t1 = threading.Thread(target=self.find_metadata, args=(f1, yt1,))
t2 = threading.Thread(target=self.find_metadata, args=(f2, yt2,))
Expand Down Expand Up @@ -124,5 +124,9 @@ def find_metadata(self, future, downloader) -> Tuple[BytesIO, bytes, dict]:
return io, data, song_info


def handle_error(exception):
raise exception()


if __name__ == '__main__':
unittest.main()

0 comments on commit 5fd2844

Please sign in to comment.