Vai al contenuto

main

main

The main module of the streaming app.

main() async

The main function that runs the streaming app.

This function initializes a StreamingSantaCroce object and runs the app. If any exception occurs during the execution of the app, an error popup is displayed with the details of the exception. The function also stops any running threads before exiting the program.

Source code in main.py
async def main() -> None:
    """
    The main function that runs the streaming app.

    This function initializes a `StreamingSantaCroce` object and runs the app.
    If any exception occurs during the execution of the app, an error popup is
    displayed with the details of the exception. The function also stops any
    running threads before exiting the program.
    """
    streaming_app = None
    try:
        streaming_app = StreamingSantaCroce()
        logging.getLogger("httpx").setLevel(logging.WARNING)
        if getattr(sys, 'frozen', False):
            # pylint: disable=possibly-used-before-assignment
            pyi_splash.close()
        await streaming_app.run_app()
    except BaseException as ex:  # pylint: disable=broad-except
        if getattr(sys, 'frozen', False):
            pyi_splash.close()
        name = ex.__class__.__name__
        msg = f"Si รจ verificato il seguente errore non gestito ({name}): {ex}"
        ctypes.windll.user32.MessageBoxW(0, msg, "ERRORE",
                                         0x10 | 0x2000 | 0x10000 | 0x40000)
        logging.critical(msg, exc_info=ex)
        if streaming_app:
            # noinspection PyBroadException
            try:
                await asyncio.wait_for(streaming_app.shutdown(), timeout=5)
            except BaseException:  # pylint: disable=broad-except
                streaming_app.main_window.destroy()
                asyncio.get_event_loop().stop()
                await asyncio.sleep(.1)
        raise RuntimeError() from ex