mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
A bit of thread refactoring
This commit is contained in:
@@ -4,6 +4,8 @@ import sys
|
||||
import math
|
||||
import urllib.request
|
||||
|
||||
import threading
|
||||
|
||||
|
||||
try:
|
||||
import winreg
|
||||
@@ -18,6 +20,26 @@ except ImportError:
|
||||
sys.exit(5)
|
||||
|
||||
|
||||
# This has been referred from
|
||||
# https://stackoverflow.com/a/6894023/6554943
|
||||
# It's because threaded functions do not return by default
|
||||
# Whereas this will return the value when `join` method
|
||||
# is called.
|
||||
class ThreadWithReturnValue(threading.Thread):
|
||||
def __init__(self, target=lambda: None, args=()):
|
||||
super().__init__(target=target, args=args)
|
||||
self._return = None
|
||||
def run(self):
|
||||
if self._target is not None:
|
||||
self._return = self._target(
|
||||
*self._args,
|
||||
**self._kwargs
|
||||
)
|
||||
def join(self, *args):
|
||||
super().join(*args)
|
||||
return self._return
|
||||
|
||||
|
||||
def merge(base, overrider):
|
||||
""" Override default dict with config dict. """
|
||||
merger = base.copy()
|
||||
|
||||
Reference in New Issue
Block a user