From fdec2356f9cba29a9cc11a1f20c699db416943aa Mon Sep 17 00:00:00 2001 From: arabcoders Date: Mon, 23 Jun 2025 12:56:00 +0300 Subject: [PATCH] Fix tasks not dispatching --- app/main.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/main.py b/app/main.py index 42cb9308..bfe62777 100644 --- a/app/main.py +++ b/app/main.py @@ -38,15 +38,10 @@ class Main: def __init__(self, is_native: bool = False): self._config = Config.get_instance(is_native=is_native) self._app = web.Application() - self.loop = asyncio.new_event_loop() self._app.on_shutdown.append(self.on_shutdown) Services.get_instance().add("app", self._app) - if self._config.debug: - self.loop.set_debug(True) - self.loop.slow_callback_duration = 0.05 - self._check_folders() caribou.upgrade(self._config.db_file, ROOT_PATH / "migrations") @@ -127,7 +122,13 @@ class Main: LOG.info(f"YTPTube {self._config.version} - started on http://{host}:{port}{self._config.base_path}") LOG.info("=" * 40) - EventBus.get_instance().sync_emit(Events.STARTED, data={"app": self._app}, loop=self.loop, wait=False) + loop = asyncio.get_event_loop() + + EventBus.get_instance().sync_emit(Events.STARTED, data={"app": self._app}, loop=loop, wait=False) + + if loop and self._config.debug: + loop.set_debug(True) + loop.slow_callback_duration = 0.05 if cb: cb() @@ -145,7 +146,7 @@ class Main: host=host, port=port, reuse_port="win32" != sys.platform, - loop=self.loop, + loop=asyncio.get_event_loop(), access_log=HTTP_LOGGER, print=started, handle_signals=cb is None,