Skip to content

Commit

Permalink
Add excepthook to pause on startup exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
deiteris committed Jul 27, 2024
1 parent f2cf50f commit be97dbb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
6 changes: 5 additions & 1 deletion server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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__
15 changes: 9 additions & 6 deletions server/client.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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))
6 changes: 1 addition & 5 deletions server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit be97dbb

Please sign in to comment.