:py:mod:`mlair.run_modules.run_environment` =========================================== .. py:module:: mlair.run_modules.run_environment .. autoapi-nested-parse:: Implementation of run environment. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: mlair.run_modules.run_environment.RunEnvironment Attributes ~~~~~~~~~~ .. autoapisummary:: mlair.run_modules.run_environment.__author__ mlair.run_modules.run_environment.__date__ .. py:data:: __author__ :annotation: = Lukas Leufen .. py:data:: __date__ :annotation: = 2019-11-25 .. py:class:: RunEnvironment(name=None, log_level_stream=None) Bases: :py:obj:`object` Basic run class to measure execution time. Either call this class by 'with' statement or delete the class instance after finishing the measurement. The duration result is logged. .. code-block:: python >>> with RunEnvironment(): INFO: RunEnvironment started ... INFO: RunEnvironment finished after 00:00:04 (hh:mm:ss) If you want to embed your custom module in a RunEnvironment, you can easily call it inside the with statement. If you want to exchange between different modules in addition, create your module as inheritance of the RunEnvironment and call it after you initialised the RunEnvironment itself. .. code-block:: python class CustomClass(RunEnvironment): def __init__(self): super().__init__() ... ... >>> with RunEnvironment(): CustomClass() INFO: RunEnvironment started INFO: CustomClass started INFO: CustomClass finished after 00:00:04 (hh:mm:ss) INFO: RunEnvironment finished after 00:00:04 (hh:mm:ss) All data that is stored in the data store will be available for all other modules that inherit from RunEnvironment as long the RunEnvironemnt base class is running. If the base class is deleted either by hand or on exit of the with statement, this storage is cleared. .. code-block:: python class CustomClassA(RunEnvironment): def __init__(self): super().__init__() self.data_store.set("testVar", 12) class CustomClassB(RunEnvironment): def __init__(self): super().__init__() self.test_var = self.data_store.get("testVar") logging.info(f"testVar = {self.test_var}") >>> with RunEnvironment(): CustomClassA() CustomClassB() INFO: RunEnvironment started INFO: CustomClassA started INFO: CustomClassA finished after 00:00:01 (hh:mm:ss) INFO: CustomClassB started INFO: testVar = 12 INFO: CustomClassB finished after 00:00:02 (hh:mm:ss) INFO: RunEnvironment finished after 00:00:03 (hh:mm:ss) .. py:attribute:: del_by_exit :annotation: = False .. py:attribute:: data_store .. py:attribute:: logger .. py:attribute:: tracker_list :annotation: = [] .. py:method:: __del__(self) Finalise class. Only stop time tracking, if not already called by exit method to prevent duplicated logging (__exit__ is always executed before __del__) it this class was used in a with statement. If instance is called as base class and not as inheritance from this class, log file is copied and data store is cleared. .. py:method:: __enter__(self) Enter run environment. .. py:method:: __exit__(self, exc_type, exc_val, exc_tb) Exit run environment. .. py:method:: __move_log_file(self) .. py:method:: __save_tracking(self) .. py:method:: __plot_tracking(self) .. py:method:: __find_file_pattern(self, name) .. py:method:: update_datastore(cls, new_data_store: mlair.helpers.datastore.DataStoreByScope, excluded_params=None, apply_full_replacement=False) :classmethod: .. py:method:: do_stuff(length=2) :staticmethod: Just a placeholder method for testing without any sense.