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

Method _check_once

pymongo/synchronous/monitor.py:291–350  ·  view source on GitHub ↗

A single attempt to call hello. Returns a ServerDescription, or raises an exception.

(self)

Source from the content-addressed store, hash-verified

289 return ServerDescription(address, error=error)
290
291 def _check_once(self) -> ServerDescription:
292 """A single attempt to call hello.
293
294 Returns a ServerDescription, or raises an exception.
295 """
296 address = self._server_description.address
297 sd = self._server_description
298
299 # XXX: "awaited" could be incorrectly set to True in the rare case
300 # the pool checkout closes and recreates a connection.
301 awaited = bool(
302 self._pool.conns and self._stream and sd.is_server_type_known and sd.topology_version
303 )
304 if self._publish:
305 assert self._listeners is not None
306 self._listeners.publish_server_heartbeat_started(address, awaited)
307
308 if self._cancel_context and self._cancel_context.cancelled:
309 self._reset_connection()
310 with self._pool.checkout() as conn:
311 if _SDAM_LOGGER.isEnabledFor(logging.DEBUG):
312 _debug_log(
313 _SDAM_LOGGER,
314 message=_SDAMStatusMessage.HEARTBEAT_START,
315 topologyId=self._topology._topology_id,
316 driverConnectionId=conn.id,
317 serverConnectionId=conn.server_connection_id,
318 serverHost=address[0],
319 serverPort=address[1],
320 awaited=awaited,
321 )
322
323 self._cancel_context = conn.cancel_context
324 # Record the connection id so we can later attach it to the failed log message.
325 self._conn_id = conn.id
326 response, round_trip_time = self._check_with_socket(conn)
327 if not response.awaitable:
328 self._rtt_monitor.add_sample(round_trip_time)
329
330 avg_rtt, min_rtt = self._rtt_monitor.get()
331 sd = ServerDescription(address, response, avg_rtt, min_round_trip_time=min_rtt)
332 if self._publish:
333 assert self._listeners is not None
334 self._listeners.publish_server_heartbeat_succeeded(
335 address, round_trip_time, response, response.awaitable
336 )
337 if _SDAM_LOGGER.isEnabledFor(logging.DEBUG):
338 _debug_log(
339 _SDAM_LOGGER,
340 message=_SDAMStatusMessage.HEARTBEAT_SUCCESS,
341 topologyId=self._topology._topology_id,
342 driverConnectionId=conn.id,
343 serverConnectionId=conn.server_connection_id,
344 serverHost=address[0],
345 serverPort=address[1],
346 awaited=awaited,
347 durationMS=round_trip_time * 1000,
348 reply=response.document,

Callers 1

_check_serverMethod · 0.95

Calls 9

_reset_connectionMethod · 0.95
_check_with_socketMethod · 0.95
_debug_logFunction · 0.90
ServerDescriptionClass · 0.90
checkoutMethod · 0.45
add_sampleMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected