prevent multiple creation of cpu usage thread

This commit is contained in:
Jakob Ketterl 2020-12-31 23:18:01 +01:00
parent 90f319ebda
commit a1cbc45b88

View File

@ -7,11 +7,13 @@ logger = logging.getLogger(__name__)
class CpuUsageThread(threading.Thread): class CpuUsageThread(threading.Thread):
sharedInstance = None sharedInstance = None
creationLock = threading.Lock()
@staticmethod @staticmethod
def getSharedInstance(): def getSharedInstance():
if CpuUsageThread.sharedInstance is None: with CpuUsageThread.creationLock:
CpuUsageThread.sharedInstance = CpuUsageThread() if CpuUsageThread.sharedInstance is None:
CpuUsageThread.sharedInstance = CpuUsageThread()
return CpuUsageThread.sharedInstance return CpuUsageThread.sharedInstance
def __init__(self): def __init__(self):