Skip to content

Commit

Permalink
Use Semaphore
Browse files Browse the repository at this point in the history
  • Loading branch information
pawlizio committed Oct 7, 2023
1 parent d7d2f23 commit 7032496
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
22 changes: 14 additions & 8 deletions pyvlx/api/command_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,21 @@ async def handle_frame(self, frame):
return True
return False

async def send(self, max_retries=3):
self.retries = 0
while self.retries < max_retries:
async def send(self):
async with self.pyvlx.sem:
await self.do_api_call()
if self.success:
return
self.retries += 1
PYVLXLOG.debug("No response from KFL200 for session_id %s, retry: %s of %s", self.session_id, self.retries, max_retries)
raise PyVLXException("Unable to send command")
if not self.success:
raise PyVLXException("Unable to send command")

# async def send(self, max_retries=3):
# self.retries = 0
# while self.retries < max_retries:
# await self.do_api_call()
# if self.success:
# return
# self.retries += 1
# PYVLXLOG.debug("No response from KFL200 for session_id %s, retry: %s of %s", self.session_id, self.retries, max_retries)
# raise PyVLXException("Unable to send command")

def request_frame(self):
"""Construct initiating frame."""
Expand Down
4 changes: 3 additions & 1 deletion pyvlx/pyvlx.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def __init__(self, path=None, host=None, password=None, loop=None, heartbeat_int
self.version = None
self.protocol_version = None
self.klf200 = Klf200Gateway(pyvlx=self)
PYVLXLOG.debug("Loading hhttps://github.com/pawlizio/pyvlx.git@handle_timeout 0.1.67")
self.sem = asyncio.Semaphore(1) # Limit parallel commands

PYVLXLOG.debug("Loading hhttps://github.com/pawlizio/pyvlx.git@handle_timeout 0.1.68")

async def connect(self):
"""Connect to KLF 200."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

PKG_ROOT = os.path.dirname(__file__)

VERSION = "0.1.67"
VERSION = "0.1.68"


def get_long_description():
Expand Down

0 comments on commit 7032496

Please sign in to comment.