From adbe74d6ea891e5bbac48c07f5e2876a828a9334 Mon Sep 17 00:00:00 2001 From: David Trattnig <david.trattnig@o94.at> Date: Tue, 27 Oct 2020 19:48:19 +0100 Subject: [PATCH] Engine as singleton. #43 #44 --- modules/core/engine.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/core/engine.py b/modules/core/engine.py index 37267c26..9b47200c 100644 --- a/modules/core/engine.py +++ b/modules/core/engine.py @@ -44,6 +44,7 @@ class Engine(): """ The Engine. """ + instance = None engine_time_offset = 0.0 logger = None @@ -68,6 +69,9 @@ class Engine(): Args: config (AuraConfig): The configuration """ + if Engine.instance: + raise Exception("Engine is already running!") + Engine.instance = self self.config = config self.plugins = dict() self.logger = logging.getLogger("AuraEngine") @@ -178,6 +182,14 @@ class Engine(): return SU.timestamp() + Engine.engine_time_offset + @staticmethod + def get_instance(): + """ + Returns the one and only engine. + """ + return Engine.instance + + def terminate(self): """ Terminates the engine and all related processes. -- GitLab