Changed the algorithm of the start method

This commit is contained in:
2025-11-01 21:00:14 +03:00
parent ffd758d9a4
commit 311870fd73
3 changed files with 9 additions and 8 deletions

View File

@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "config_manager"
version = "1.2.0"
version = "1.2.1"
description = "Config manager for building applications"
authors = [
{ name = "Aleksei Zosimov", email = "lesha.spb@gmail.com" }

View File

@@ -104,21 +104,21 @@ class ConfigManager:
finally:
self.logger.info("ConfigManager stopped")
def start(self) -> None:
"""Запускает менеджер конфигурации в текущем event loop"""
async def start(self) -> None:
if self._task is not None and not self._task.done():
self.logger.warning("ConfigManager is already running")
return
try:
self._loop = asyncio.get_running_loop()
except RuntimeError:
self.logger.error("start() must be called from within an async context")
raise
self._task = self._loop.create_task(self._run())
self.logger.info("ConfigManager task created")
async def stop(self) -> None:
"""Останавливает менеджер конфигурации и ожидает завершения"""
if self._task is None:

View File

@@ -21,10 +21,11 @@ class MyApp(ConfigManager):
async def main():
app = MyApp("config.yaml")
app.start()
await app.start()
logger.info("App started")
await asyncio.sleep(20)
await app.stop()
while True:
await asyncio.sleep(1)
if __name__ == "__main__":
asyncio.run(main())