From ccee84e78b3b20755f23354b2baa0761ecc8b898 Mon Sep 17 00:00:00 2001 From: Koltan Hauersperger Date: Wed, 9 Oct 2024 10:47:35 -0400 Subject: [PATCH 1/3] feat: catch exception and use timeout --- j1939/Dm14Query.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/j1939/Dm14Query.py b/j1939/Dm14Query.py index 8c79d9a..31ffc6a 100644 --- a/j1939/Dm14Query.py +++ b/j1939/Dm14Query.py @@ -239,9 +239,15 @@ def read( self._send_dm14(7) self.state = QueryState.WAIT_FOR_SEED # wait for operation completed DM15 message - raw_bytes = self.data_queue.get(block=True, timeout=1) + raw_bytes = None + try: + raw_bytes = self.data_queue.get(block=True, timeout=max_timeout) + except queue.Empty: + if self.state is QueryState.WAIT_FOR_SEED: + raise RuntimeError("No response from server") + pass for _ in range(self.exception_queue.qsize()): - raise self.exception_queue.get(block=False, timeout=1) + raise self.exception_queue.get(block=False, timeout=max_timeout) if raw_bytes: if self.return_raw_bytes: return raw_bytes From 741d087367f97e2d6dd2e7ba0a73af6379588e93 Mon Sep 17 00:00:00 2001 From: Koltan Hauersperger Date: Wed, 9 Oct 2024 10:55:19 -0400 Subject: [PATCH 2/3] chore: use max_timeout --- j1939/Dm14Query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/j1939/Dm14Query.py b/j1939/Dm14Query.py index 31ffc6a..e8ad385 100644 --- a/j1939/Dm14Query.py +++ b/j1939/Dm14Query.py @@ -288,7 +288,7 @@ def write( try: self.data_queue.get(block=True, timeout=max_timeout) for _ in range(self.exception_queue.qsize()): - raise self.exception_queue.get(block=False, timeout=1) + raise self.exception_queue.get(block=False, timeout=max_timeout) except queue.Empty: if self.state is QueryState.WAIT_FOR_SEED: raise RuntimeError("No response from server") From 88bba6590784e96657b2fdf8c84daa6eca0e5282 Mon Sep 17 00:00:00 2001 From: Koltan Hauersperger Date: Wed, 9 Oct 2024 11:16:22 -0400 Subject: [PATCH 3/3] test: fix unittest --- test/test_memory_access.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_memory_access.py b/test/test_memory_access.py index 8c64337..31d9c7b 100644 --- a/test/test_memory_access.py +++ b/test/test_memory_access.py @@ -575,7 +575,7 @@ def test_dm14_read_timeout_error(feeder): Tests that the DM14 read query can react to timeout errors correctly :param feeder: can message feeder """ - with pytest.raises(queue.Empty) as excinfo: + with pytest.raises(RuntimeError) as excinfo: feeder.can_messages = [ ( Feeder.MsgType.CANTX,