A bit of thread refactoring

This commit is contained in:
Ritiek Malhotra
2020-04-12 17:09:15 +05:30
parent a253c308a6
commit 9a088ee26d
5 changed files with 69 additions and 57 deletions

View File

@@ -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()