From 93986d97672f2a7bbfd11929ad8f5c7dc7181b5a Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Fri, 12 Nov 2021 15:12:51 +0300 Subject: add timeout while waiting for i2c calls --- si7021d | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'si7021d') diff --git a/si7021d b/si7021d index 123fc39..2a1e6c6 100644 --- a/si7021d +++ b/si7021d @@ -38,8 +38,12 @@ async def handle_client(reader, writer): break if request == 'read': - rh, temp = await si7021_read() - data = dict(humidity=rh, temp=temp) + try: + rh, temp = await asyncio.wait_for(si7021_read(), timeout=3) + data = dict(humidity=rh, temp=temp) + except asyncio.TimeoutError as e: + logger.exception(e) + data = dict(error='i2c call timed out') else: data = dict(error='invalid request') -- cgit v1.2.3