From be97dbb24795e64f104b630ab19230ef2b537dcb Mon Sep 17 00:00:00 2001 From: Yury Date: Sat, 27 Jul 2024 13:39:53 +0300 Subject: [PATCH] Add excepthook to pause on startup exceptions --- server/app.py | 6 +++++- server/client.py | 15 +++++++++------ server/main.py | 6 +----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/server/app.py b/server/app.py index ecba728ac..9a981be81 100644 --- a/server/app.py +++ b/server/app.py @@ -22,4 +22,8 @@ voice_changer_manager = VoiceChangerManager(settings) fastapi = MMVC_Rest.get_instance(voice_changer_manager, settings.model_dir, settings.allowed_origins, settings.port) -socketio = MMVC_SocketIOApp.get_instance(fastapi, voice_changer_manager, settings.allowed_origins, settings.port) \ No newline at end of file +socketio = MMVC_SocketIOApp.get_instance(fastapi, voice_changer_manager, settings.allowed_origins, settings.port) + +# NOTE: Bundled executable overrides excepthook to pause on exception during startup. +# Here we revert to original excepthook once all initialization is done. +sys.excepthook = sys.__excepthook__ \ No newline at end of file diff --git a/server/client.py b/server/client.py index 14c0177c8..e5aa06cab 100644 --- a/server/client.py +++ b/server/client.py @@ -1,5 +1,12 @@ -import asyncio +import sys + +def pause_excepthook(type, value, traceback, oldhook=sys.excepthook): + oldhook(type, value, traceback) + input('\nPress Enter to continue...') +sys.excepthook = pause_excepthook + +import asyncio from main import setupArgParser, main from utils.strtobool import strtobool @@ -11,8 +18,4 @@ parser.add_argument("--launch-browser", type=strtobool, default=True, help="Automatically launches web browser and opens the voice changer's interface.") args, _ = parser.parse_known_args() - try: - asyncio.run(main(args)) - except Exception as e: - logger.exception(e) - input('Press Enter to continue...') + asyncio.run(main(args)) \ No newline at end of file diff --git a/server/main.py b/server/main.py index c2d228e8b..a413f6450 100644 --- a/server/main.py +++ b/server/main.py @@ -145,8 +145,4 @@ async def main(args): args, _ = parser.parse_known_args() args.launch_browser = False - try: - asyncio.run(main(args)) - except Exception as e: - logger.exception(e) - input('Press Enter to continue...') + asyncio.run(main(args))