fix: Add timeout to wait_for_connection (#2885)
This commit is contained in:
parent
2ee7180aa0
commit
bba7614012
1 changed files with 4 additions and 1 deletions
|
|
@ -440,11 +440,14 @@ class NWCConnection:
|
||||||
logger.error("Error closing subscription: " + str(e))
|
logger.error("Error closing subscription: " + str(e))
|
||||||
return subscription
|
return subscription
|
||||||
|
|
||||||
async def _wait_for_connection(self):
|
async def _wait_for_connection(self, timeout: int = 60 * 2):
|
||||||
"""
|
"""
|
||||||
Waits until the connection is ready
|
Waits until the connection is ready
|
||||||
"""
|
"""
|
||||||
|
t = time.time()
|
||||||
while not self.connected:
|
while not self.connected:
|
||||||
|
if time.time() - t > timeout:
|
||||||
|
raise Exception("Connection timeout, cannot connect to NWC service")
|
||||||
if self._is_shutting_down():
|
if self._is_shutting_down():
|
||||||
raise Exception("Connection is closing")
|
raise Exception("Connection is closing")
|
||||||
logger.debug("Waiting for connection...")
|
logger.debug("Waiting for connection...")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue