summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyagl/services/base.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/pyagl/services/base.py b/pyagl/services/base.py
index d25f222..b64c256 100644
--- a/pyagl/services/base.py
+++ b/pyagl/services/base.py
@@ -72,6 +72,8 @@ class AFBResponse:
info: str
def __init__(self, data: list):
+ if not isinstance(data, list):
+ raise TypeError('data parameter is not list type')
if type(data[0]) is not int:
logging.debug(f'Received a response with non-integer message type {binascii.hexlify(data[0])}')
raise ValueError('Received a response with non-integer message type')
@@ -99,7 +101,7 @@ class AFBResponse:
self.msgid = int(data[1])
self.status = data[2]['request'].get('status')
self.info = data[2]['request'].get('info')
-
+ self.data = data[2]['request'].get('data')
def __str__(self): # for debugging purposes
if self.type == AFBT.EVENT:
@@ -320,12 +322,21 @@ class AGLBaseService:
result = check_output(f'systemctl start {servicename}', shell=True)
print(result)
- async def listener(self, stdout: bool = False):
+ async def listener(self, stdout: bool = False, timeout=None):
while True:
- raw = await self.response()
- data = AFBResponse(raw)
- if stdout: print(data)
- yield data
+ raw = None
+ try:
+ if timeout is not None:
+ raw = await asyncio.wait_for(self.response(), timeout=timeout)
+ else:
+ raw = await asyncio.wait_for(self.response(), timeout=self.timeout)
+ data = AFBResponse(raw)
+ if stdout: print(data)
+ yield data
+
+ except asyncio.TimeoutError:
+ self.logger.warning("Response wait timed out")
+ yield None
async def response(self):
try: