OpenCyphal / yakut

Simple CLI tool for diagnostics and debugging of Cyphal networks
https://opencyphal.org
MIT License
49 stars 10 forks source link

SIGINT may occasionally result in the stack trace being printed #62

Open pavel-kirienko opened 2 years ago

pavel-kirienko commented 2 years ago

"Exception ignored in" reports should be suppressed entirely. Here's an example where a publishing command was interrupted normally, and the Python runtime printed the unwanted stack trace:

$ y pub -T 0.01 22:reg.udral.service.actuator.common.sp.vector6 '!$ "[0,0,0,300,0,0]"'
Exception ignored in: <coroutine object publish at 0x7f65cd3d86d0>
Traceback (most recent call last):
  File "/home/groom/.local/lib/python3.10/site-packages/yakut/cmd/publish/_cmd.py", line 311, in publish
    pycyphal.util.broadcast(finalizers[::-1])()
  File "/home/groom/.local/lib/python3.10/site-packages/pycyphal/util/_broadcast.py", line 46, in delegate
    r: typing.Union[R, Exception] = fn(*args, **kwargs)
  File "/home/groom/.local/lib/python3.10/site-packages/yakut/cmd/publish/_executor.py", line 75, in close
    pycyphal.util.broadcast(p.close for p in self._publications)()
  File "/home/groom/.local/lib/python3.10/site-packages/pycyphal/util/_broadcast.py", line 46, in delegate
    r: typing.Union[R, Exception] = fn(*args, **kwargs)
  File "/home/groom/.local/lib/python3.10/site-packages/yakut/cmd/publish/_executor.py", line 135, in close
    self._publisher.close()
  File "/home/groom/.local/lib/python3.10/site-packages/pycyphal/presentation/_port/_publisher.py", line 142, in close
    impl.remove_proxy()
  File "/home/groom/.local/lib/python3.10/site-packages/pycyphal/presentation/_port/_publisher.py", line 212, in remove_proxy
    self.close()  # RAII auto-close
  File "/home/groom/.local/lib/python3.10/site-packages/pycyphal/presentation/_port/_publisher.py", line 223, in close
    self._maybe_finalizer([self.transport_session])
  File "/home/groom/.local/lib/python3.10/site-packages/pycyphal/presentation/_presentation.py", line 394, in finalizer
    ts.close()
  File "/home/groom/.local/lib/python3.10/site-packages/pycyphal/transport/redundant/_session/_output.py", line 316, in close
    s.close()
  File "/home/groom/.local/lib/python3.10/site-packages/pycyphal/transport/redundant/_session/_output.py", line 86, in close
    self.worker.result()
  File "/home/groom/.local/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/groom/.local/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/groom/.local/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/groom/.local/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/groom/.local/lib/python3.10/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/groom/.local/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/groom/.local/lib/python3.10/site-packages/yakut/main.py", line 332, in proxy
    for e in loop.run_until_complete(asyncio.gather(*orphans, return_exceptions=True)):
  File "/usr/lib/python3.10/asyncio/base_events.py", line 633, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 600, in run_forever
    self._run_once()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1896, in _run_once
    handle._run()
  File "/usr/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/groom/.local/lib/python3.10/site-packages/pycyphal/transport/redundant/_session/_output.py", line 331, in _inferior_worker_task
    result = await ses.send(wrk.transfer, wrk.monotonic_deadline)
  File "/home/groom/.local/lib/python3.10/site-packages/pycyphal/transport/can/_session/_output.py", line 206, in send
    return await self._do_send(can_id, transfer, monotonic_deadline)
  File "/home/groom/.local/lib/python3.10/site-packages/pycyphal/transport/can/_session/_output.py", line 163, in _do_send
    if await self._send_handler(transaction):
  File "/home/groom/.local/lib/python3.10/site-packages/pycyphal/transport/can/_can.py", line 329, in _do_send
    num_sent = await self._maybe_media.send(
  File "/home/groom/.local/lib/python3.10/site-packages/pycyphal/transport/can/media/socketcan/_socketcan.py", line 140, in send
    await asyncio.wait_for(
  File "/usr/lib/python3.10/asyncio/tasks.py", line 435, in wait_for
    return fut.result()
  File "/home/groom/.local/lib/python3.10/site-packages/yakut/main.py", line 314, in proxy
    return loop.run_until_complete(f(*args, **kwargs))
  File "/usr/lib/python3.10/asyncio/base_events.py", line 633, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 600, in run_forever
    self._run_once()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1896, in _run_once
    handle._run()
  File "/usr/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/lib/python3.10/asyncio/selector_events.py", line 441, in sock_sendall
    n = sock.send(data)
KeyboardInterrupt: