**INTERNAL** Terminal cleanup for the streaming op: end the observability span/meter and release the executor. Invoked from every terminal branch of ``__anext__`` -- including cancellation -- so that ``asyncio.CancelledError`` (a ``BaseException``, not an ``Excepti
(self, exc_val=None)
| 112 | self._tp_executor.shutdown(wait=False) |
| 113 | |
| 114 | def _finalize(self, exc_val=None): |
| 115 | """ |
| 116 | **INTERNAL** |
| 117 | |
| 118 | Terminal cleanup for the streaming op: end the observability span/meter and release the |
| 119 | executor. Invoked from every terminal branch of ``__anext__`` -- including cancellation -- |
| 120 | so that ``asyncio.CancelledError`` (a ``BaseException``, not an ``Exception``) cannot bypass |
| 121 | teardown and leak the span/meter or orphan the streaming result and its executor thread. |
| 122 | """ |
| 123 | self._process_core_span(exc_val=exc_val) |
| 124 | if exc_val is not None and self._streaming_result is not None: |
| 125 | # Cancellation/error: unblock a worker still waiting on the C++ core so its executor |
| 126 | # thread is released promptly instead of waiting for the whole server-side operation |
| 127 | # to finish. Normal completion (exc_val is None) skips this so trailing metadata can |
| 128 | # still be read from the streaming result. |
| 129 | self._streaming_result.cancel() |
| 130 | self._shutdown_executor() |
| 131 | |
| 132 | async def __anext__(self): |
| 133 | return await stream_anext(self) |
nothing calls this directly
no test coverage detected