diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-11-12 15:12:51 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-11-12 15:12:51 +0300 |
commit | 93986d97672f2a7bbfd11929ad8f5c7dc7181b5a (patch) | |
tree | bd1d90fc68e6000a0964aca118e8aeed8727c21c | |
parent | 585a130ecd828b03cf06ae1cfbedac49ad01e7ec (diff) |
add timeout while waiting for i2c calls
-rw-r--r-- | si7021d | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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') |