Skip to content

Commit 7c35eab

Browse files
fix: close stream on error to prevent hanging
Add aclose() in exception handlers to ensure the gRPC stream is terminated even when an error occurs during classification.
1 parent 2ea690e commit 7c35eab

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

examples/utils/streaming_classify_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ async def classify_images(
138138

139139
except Exception:
140140
logger.exception("Error during classification")
141+
# Always close the stream on error to prevent hanging
142+
await results.aclose()
141143
if received_count == 0:
142144
raise
143145
finally:
@@ -226,6 +228,8 @@ async def classify_images_break_on_first_result(
226228

227229
except Exception:
228230
logger.exception("Error during classification")
231+
# Always close the stream on error to prevent hanging
232+
await results.aclose()
229233
if received_count == 0:
230234
raise
231235

tests/functional/e2e/test_classify_single.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
load_test_cases,
1515
)
1616

17-
TEST_CASES = load_test_cases("benign_model")
17+
TEST_CASES = load_test_cases("live_model")
1818

1919
FP_ERROR_TOLERANCE = 1e-4
2020

tests/utils/streaming_classify_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ async def classify_images(
133133

134134
except Exception:
135135
logger.exception("Error during classification")
136+
# Always close the stream on error to prevent hanging
137+
await results.aclose()
136138
if received_count == 0:
137139
raise
138140
finally:
@@ -219,6 +221,8 @@ async def classify_images_break_on_first_result(
219221

220222
except Exception:
221223
logger.exception("Error during classification")
224+
# Always close the stream on error to prevent hanging
225+
await results.aclose()
222226
if received_count == 0:
223227
raise
224228

0 commit comments

Comments
 (0)