2022-01-23 22:56:27 +00:00
|
|
|
# Python imports
|
|
|
|
import builtins
|
2023-01-29 06:06:52 +00:00
|
|
|
import threading
|
2023-10-19 00:00:33 +00:00
|
|
|
import sys
|
2022-01-23 22:56:27 +00:00
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
|
|
|
|
# Application imports
|
2024-01-12 01:35:04 +00:00
|
|
|
from libs.db import DB
|
|
|
|
from libs.event_system import EventSystem
|
|
|
|
from libs.endpoint_registry import EndpointRegistry
|
|
|
|
from libs.keybindings import Keybindings
|
|
|
|
from libs.logger import Logger
|
|
|
|
from libs.settings_manager.manager import SettingsManager
|
2022-02-25 23:53:58 +00:00
|
|
|
|
|
|
|
|
2023-10-07 22:12:02 +00:00
|
|
|
|
2022-09-05 23:01:39 +00:00
|
|
|
# NOTE: Threads WILL NOT die with parent's destruction.
|
|
|
|
def threaded_wrapper(fn):
|
|
|
|
def wrapper(*args, **kwargs):
|
2023-11-19 21:37:11 +00:00
|
|
|
thread = threading.Thread(target = fn, args = args, kwargs = kwargs, daemon = False)
|
|
|
|
thread.start()
|
|
|
|
return thread
|
2022-09-05 23:01:39 +00:00
|
|
|
return wrapper
|
2022-01-23 22:56:27 +00:00
|
|
|
|
2022-09-05 23:01:39 +00:00
|
|
|
# NOTE: Threads WILL die with parent's destruction.
|
|
|
|
def daemon_threaded_wrapper(fn):
|
|
|
|
def wrapper(*args, **kwargs):
|
2023-11-19 21:37:11 +00:00
|
|
|
thread = threading.Thread(target = fn, args = args, kwargs = kwargs, daemon = True)
|
|
|
|
thread.start()
|
|
|
|
return thread
|
2022-09-05 23:01:39 +00:00
|
|
|
return wrapper
|
2022-01-23 22:56:27 +00:00
|
|
|
|
|
|
|
|
2021-10-11 04:33:58 +00:00
|
|
|
|
2022-01-23 22:56:27 +00:00
|
|
|
# NOTE: Just reminding myself we can add to builtins two different ways...
|
|
|
|
# __builtins__.update({"event_system": Builtins()})
|
|
|
|
builtins.app_name = "<change_me>"
|
2023-09-23 05:12:36 +00:00
|
|
|
|
2022-10-14 01:58:44 +00:00
|
|
|
builtins.keybindings = Keybindings()
|
2022-02-25 23:53:58 +00:00
|
|
|
builtins.event_system = EventSystem()
|
2022-09-05 23:01:39 +00:00
|
|
|
builtins.endpoint_registry = EndpointRegistry()
|
2023-07-30 05:36:52 +00:00
|
|
|
builtins.settings_manager = SettingsManager()
|
2023-11-19 21:37:11 +00:00
|
|
|
builtins.db = DB()
|
2023-09-18 01:08:09 +00:00
|
|
|
|
|
|
|
settings_manager.load_settings()
|
|
|
|
|
2023-07-30 05:36:52 +00:00
|
|
|
builtins.settings = settings_manager.settings
|
|
|
|
builtins.logger = Logger(settings_manager.get_home_config_path(), \
|
|
|
|
_ch_log_lvl=settings.debugging.ch_log_lvl, \
|
|
|
|
_fh_log_lvl=settings.debugging.fh_log_lvl).get_logger()
|
2022-10-14 01:58:44 +00:00
|
|
|
|
2022-09-05 23:01:39 +00:00
|
|
|
builtins.threaded = threaded_wrapper
|
|
|
|
builtins.daemon_threaded = daemon_threaded_wrapper
|
2023-10-19 00:00:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def custom_except_hook(exc_type, exc_value, exc_traceback):
|
|
|
|
if issubclass(exc_type, KeyboardInterrupt):
|
|
|
|
sys.__excepthook__(exc_type, exc_value, exc_traceback)
|
|
|
|
return
|
|
|
|
|
|
|
|
logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
|
|
|
|
|
2023-11-19 21:37:11 +00:00
|
|
|
sys.excepthook = custom_except_hook
|