avoid race condition
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Thu, 15 Jun 2023 19:09:47 +0000 (21:09 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Thu, 15 Jun 2023 19:09:47 +0000 (21:09 +0200)
music_assistant/server/server.py

index aae7f37d97fe27ece970e316ef054682b2c0d060..8972da8295ac04b48a444a71026326ce9870f983 100644 (file)
@@ -65,13 +65,12 @@ class MusicAssistant:
 
     loop: asyncio.AbstractEventLoop
     http_session: ClientSession
+    zeroconf: Zeroconf
 
     def __init__(self, storage_path: str) -> None:
         """Initialize the MusicAssistant Server."""
         self.storage_path = storage_path
         self.base_ip = get_ip()
-        # shared zeroconf instance
-        self.zeroconf = Zeroconf(interfaces=InterfaceChoice.All)
         # we dynamically register command handlers which can be consumed by the apis
         self.command_handlers: dict[str, APICommandHandler] = {}
         self._subscribers: set[EventSubscriptionType] = set()
@@ -93,6 +92,8 @@ class MusicAssistant:
     async def start(self) -> None:
         """Start running the Music Assistant server."""
         self.loop = asyncio.get_running_loop()
+        # create shared zeroconf instance
+        self.zeroconf = Zeroconf(interfaces=InterfaceChoice.All)
         # create shared aiohttp ClientSession
         self.http_session = ClientSession(
             loop=self.loop,