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

Method _check_with_socket

pymongo/synchronous/monitor.py:352–373  ·  view source on GitHub ↗

Return (Hello, round_trip_time). Can raise ConnectionFailure or OperationFailure.

(self, conn: Connection)

Source from the content-addressed store, hash-verified

350 return sd
351
352 def _check_with_socket(self, conn: Connection) -> tuple[Hello, float]: # type: ignore[type-arg]
353 """Return (Hello, round_trip_time).
354
355 Can raise ConnectionFailure or OperationFailure.
356 """
357 start = time.monotonic()
358 if conn.more_to_come:
359 # Read the next streaming hello (MongoDB 4.4+).
360 response = Hello(conn._next_reply(), awaitable=True)
361 elif (
362 self._stream and conn.performed_handshake and self._server_description.topology_version
363 ):
364 # Initiate streaming hello (MongoDB 4.4+).
365 response = conn._hello(
366 self._server_description.topology_version,
367 self._settings.heartbeat_frequency,
368 )
369 else:
370 # New connection handshake or polling hello (MongoDB <4.4).
371 response = conn._hello(None, None)
372 duration = _monotonic_duration(start)
373 return response, duration
374
375
376class SrvMonitor(MonitorBase):

Callers 1

_check_onceMethod · 0.95

Calls 4

HelloClass · 0.90
_monotonic_durationFunction · 0.70
_next_replyMethod · 0.45
_helloMethod · 0.45

Tested by

no test coverage detected