forked from M-Labs/artiq
1
0
Fork 0

moninj,corelog: fix/cleanup exception handling (#1897)

This commit is contained in:
Sebastien Bourdeauducq 2022-07-02 17:48:18 +08:00
parent 02b086c9e5
commit 388b81af19
2 changed files with 46 additions and 40 deletions

View File

@ -91,6 +91,10 @@ class CommMonInj:
self.injection_status_cb(channel, override, value) self.injection_status_cb(channel, override, value)
else: else:
raise ValueError("Unknown packet type", ty) raise ValueError("Unknown packet type", ty)
except asyncio.CancelledError:
raise
except:
logger.error("Moninj connection terminating with exception", exc_info=True)
finally: finally:
if self.disconnect_cb is not None: if self.disconnect_cb is not None:
self.disconnect_cb() self.disconnect_cb()

View File

@ -40,6 +40,7 @@ async def get_logs_sim(host):
async def get_logs(host): async def get_logs(host):
try:
reader, writer = await async_open_connection( reader, writer = await async_open_connection(
host, host,
1380, 1380,
@ -78,6 +79,10 @@ async def get_logs(host):
name = 'firmware.' + m.group(2).replace('::', '.') name = 'firmware.' + m.group(2).replace('::', '.')
text = m.group(3) text = m.group(3)
log_with_name(name, level, text) log_with_name(name, level, text)
except asyncio.CancelledError:
raise
except:
logger.error("Logging connection terminating with exception", exc_info=True)
def main(): def main():
@ -99,8 +104,7 @@ def main():
_, pending = loop.run_until_complete(asyncio.wait( _, pending = loop.run_until_complete(asyncio.wait(
[signal_handler.wait_terminate(), [signal_handler.wait_terminate(),
server.wait_terminate(), server.wait_terminate(),
get_logs_task get_logs_task],
],
return_when=asyncio.FIRST_COMPLETED)) return_when=asyncio.FIRST_COMPLETED))
for task in pending: for task in pending:
task.cancel() task.cancel()
@ -108,8 +112,6 @@ def main():
loop.run_until_complete(server.stop()) loop.run_until_complete(server.stop())
finally: finally:
pass pass
except Exception:
logger.error("Termination due to exception", exc_info=True)
finally: finally:
signal_handler.teardown() signal_handler.teardown()
finally: finally: