Skip to content

Commit 18027a9

Browse files
authored
Fixed unbound error on timeout with PythonIsotpConnection (#198)
1 parent fda7a42 commit 18027a9

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

udsoncan/client.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,33 +2157,33 @@ def send_request(self, request: Request, timeout: int = -1) -> Optional[Response
21572157
done_receiving = True
21582158
self.logger.debug("Waiting for server response")
21592159

2160-
try:
2161-
if not respect_overall_timeout or (respect_overall_timeout and time.time() + single_request_timeout < overall_timeout_time):
2162-
timeout_type_used = 'single_request'
2163-
timeout_value = single_request_timeout
2164-
else:
2165-
timeout_type_used = 'overall'
2166-
timeout_value = max(overall_timeout_time - time.time(), 0)
2160+
if not respect_overall_timeout or (respect_overall_timeout and time.time() + single_request_timeout < overall_timeout_time):
2161+
timeout_type_used = 'single_request'
2162+
timeout_value = single_request_timeout
2163+
else:
2164+
timeout_type_used = 'overall'
2165+
timeout_value = max(overall_timeout_time - time.time(), 0)
21672166

2167+
try:
21682168
recv_payload = self.conn.wait_frame(timeout=timeout_value, exception=True)
21692169
except TimeoutException:
2170-
if timeout_type_used == 'single_request':
2171-
timeout_name_to_report = 'P2* timeout' if using_p2_star else 'P2 timeout'
2172-
elif timeout_type_used == 'overall':
2173-
timeout_name_to_report = 'Global request timeout'
2174-
else: # Shouldn't go here.
2175-
timeout_name_to_report = 'Timeout'
21762170
timed_out = True
2177-
21782171
except Exception as e:
21792172
raise e
21802173

21812174
if timed_out or recv_payload is None:
21822175
if spr_used:
21832176
return None
2177+
if timeout_type_used == 'single_request':
2178+
timeout_name_to_report = 'P2* timeout' if using_p2_star else 'P2 timeout'
2179+
elif timeout_type_used == 'overall':
2180+
timeout_name_to_report = 'Global request timeout'
2181+
else: # Shouldn't go here.
2182+
timeout_name_to_report = 'Timeout'
2183+
21842184
raise TimeoutException('Did not receive response in time. %s time has expired (timeout=%.3f sec)' %
21852185
(timeout_name_to_report, timeout_value))
2186-
2186+
21872187
response = Response.from_payload(recv_payload)
21882188
self.last_response = response
21892189
self.logger.debug("Received response from server")

0 commit comments

Comments
 (0)