MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / _BoundSessionContext

Class _BoundSessionContext

pymongo/synchronous/client_session.py:190–207  ·  view source on GitHub ↗

Context manager returned by ClientSession.bind() that manages bound state.

Source from the content-addressed store, hash-verified

188
189
190class _BoundSessionContext:
191 """Context manager returned by ClientSession.bind() that manages bound state."""
192
193 def __init__(self, session: ClientSession, end_session: bool) -> None:
194 self._session = session
195 self._session_token: Optional[Token[ClientSession]] = None
196 self._end_session = end_session
197
198 def __enter__(self) -> ClientSession:
199 self._session_token = _SESSION.set(self._session) # type: ignore[assignment]
200 return self._session
201
202 def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
203 if self._session_token:
204 _SESSION.reset(self._session_token) # type: ignore[arg-type]
205 self._session_token = None
206 if self._end_session:
207 self._session.end_session()
208
209
210class SessionOptions:

Callers 1

bindMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected