Start a logical session. This method takes the same parameters as :class:`~pymongo.client_session.SessionOptions`. See the :mod:`~pymongo.client_session` module for details and examples. A :class:`~pymongo.client_session.ClientSession` may only be used with
(
self,
causal_consistency: Optional[bool] = None,
default_transaction_options: Optional[client_session.TransactionOptions] = None,
snapshot: Optional[bool] = False,
)
| 1394 | return client_session.ClientSession(self, server_session, opts, implicit) |
| 1395 | |
| 1396 | def start_session( |
| 1397 | self, |
| 1398 | causal_consistency: Optional[bool] = None, |
| 1399 | default_transaction_options: Optional[client_session.TransactionOptions] = None, |
| 1400 | snapshot: Optional[bool] = False, |
| 1401 | ) -> client_session.ClientSession: |
| 1402 | """Start a logical session. |
| 1403 | |
| 1404 | This method takes the same parameters as |
| 1405 | :class:`~pymongo.client_session.SessionOptions`. See the |
| 1406 | :mod:`~pymongo.client_session` module for details and examples. |
| 1407 | |
| 1408 | A :class:`~pymongo.client_session.ClientSession` may only be used with |
| 1409 | the MongoClient that started it. :class:`ClientSession` instances are |
| 1410 | **not thread-safe or fork-safe**. They can only be used by one thread |
| 1411 | or process at a time. A single :class:`ClientSession` cannot be used |
| 1412 | to run multiple operations concurrently. |
| 1413 | |
| 1414 | :return: An instance of :class:`~pymongo.client_session.ClientSession`. |
| 1415 | |
| 1416 | .. versionadded:: 3.6 |
| 1417 | """ |
| 1418 | return self._start_session( |
| 1419 | False, |
| 1420 | causal_consistency=causal_consistency, |
| 1421 | default_transaction_options=default_transaction_options, |
| 1422 | snapshot=snapshot, |
| 1423 | ) |
| 1424 | |
| 1425 | def _ensure_session(self, session: Optional[ClientSession] = None) -> Optional[ClientSession]: |
| 1426 | """If provided session and bound session are None, lend a temporary session.""" |