diff --git a/src/lvmnps/actor/commands/scripts.py b/src/lvmnps/actor/commands/scripts.py index 8b67c46..002f009 100644 --- a/src/lvmnps/actor/commands/scripts.py +++ b/src/lvmnps/actor/commands/scripts.py @@ -26,7 +26,7 @@ def validate_nps(command: NPSCommand): """Checks that the NPS implements scripting.""" nps = command.actor.nps - print(nps.implementations.get("scripting")) + if nps.implementations.get("scripting", False) is False: command.fail("Scripting not allowed for this NPS.") return False diff --git a/src/lvmnps/nps/implementations/dli.py b/src/lvmnps/nps/implementations/dli.py index 2799e40..5bea9ee 100644 --- a/src/lvmnps/nps/implementations/dli.py +++ b/src/lvmnps/nps/implementations/dli.py @@ -8,6 +8,7 @@ from __future__ import annotations +import asyncio import warnings import httpx @@ -44,9 +45,13 @@ class APIClient: def __post_init__(self): self.client: httpx.AsyncClient | None = None + self.lock = asyncio.Lock() + async def __aenter__(self): """Yields a new client.""" + await self.lock.acquire() + log.debug(f"Creating async client to {self.base_url!r} with digest.") auth = httpx.DigestAuth(self.user, self.password.get_secret_value()) @@ -61,6 +66,8 @@ async def __aenter__(self): async def __aexit__(self, exc_type, exc, tb): """Closes the client.""" + self.lock.release() + if self.client and not self.client.is_closed: log.debug("Closing async client.") await self.client.aclose()