MCPcopy Create free account
hub / github.com/couchbase/couchbase-python-client / _finalize

Method _finalize

acouchbase/views.py:114–130  ·  view source on GitHub ↗

**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)

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 3

_shutdown_executorMethod · 0.95
cancelMethod · 0.80
_process_core_spanMethod · 0.45

Tested by

no test coverage detected