diff options
author | Carlos Chinchilla <cachinchilla@google.com> | 2023-07-27 01:21:04 +0000 |
---|---|---|
committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-07-27 01:21:04 +0000 |
commit | 598599c0d2448391a0cec6ca03c00a76650a063e (patch) | |
tree | c042806ab675de5c31a55d061f7dd468d56c2d88 /pw_hdlc/py | |
parent | 3b68c84d2909ecf33700ad7967c3041663d39f78 (diff) | |
download | pigweed-598599c0d2448391a0cec6ca03c00a76650a063e.tar.gz |
pw_{console,hdlc}: Detect comms errors in Python
- Log raised exceptions when reading a communication transport.
- Detect socket disconnects when reading or writing.
- Make console try to reconnect on socket disconnect events.
Change-Id: I2e87390d1d340c31e2963936c76d91f08e3baecd
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/155814
Pigweed-Auto-Submit: Carlos Chinchilla <cachinchilla@google.com>
Reviewed-by: Taylor Cramer <cramertj@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'pw_hdlc/py')
-rw-r--r-- | pw_hdlc/py/pw_hdlc/rpc.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/pw_hdlc/py/pw_hdlc/rpc.py b/pw_hdlc/py/pw_hdlc/rpc.py index b1998830e..64bca2051 100644 --- a/pw_hdlc/py/pw_hdlc/rpc.py +++ b/pw_hdlc/py/pw_hdlc/rpc.py @@ -280,8 +280,12 @@ class HdlcRpcClient(RpcClient): _LOG.exception('Exception in HDLC frame handler thread') decoder = FrameDecoder() + + def on_read_error(exc: Exception) -> None: + _LOG.error(str(exc)) + reader = DataReaderAndExecutor( - read, lambda exc: None, decoder.process_valid_frames, handle_frame + read, on_read_error, decoder.process_valid_frames, handle_frame ) super().__init__(reader, paths_or_modules, channels, client_impl) @@ -312,8 +316,11 @@ class NoEncodingSingleChannelRpcClient(RpcClient): def process_data(data: bytes): yield data + def on_read_error(exc: Exception) -> None: + _LOG.error(str(exc)) + reader = DataReaderAndExecutor( - read, lambda exc: None, process_data, self.handle_rpc_packet + read, on_read_error, process_data, self.handle_rpc_packet ) super().__init__(reader, paths_or_modules, [channel], client_impl) |