MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / _run

Method _run

pymongo/asynchronous/monitor.py:212–252  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

210 await self._pool.reset()
211
212 async def _run(self) -> None:
213 try:
214 prev_sd = self._server_description
215 try:
216 self._server_description = await self._check_server()
217 except _OperationCancelled as exc:
218 _sanitize(exc)
219 # Already closed the connection, wait for the next check.
220 self._server_description = ServerDescription(
221 self._server_description.address, error=exc
222 )
223 if prev_sd.is_server_type_known:
224 # Immediately retry since we've already waited 500ms to
225 # discover that we've been cancelled.
226 self._executor.skip_sleep()
227 return
228
229 # Update the Topology and clear the server pool on error.
230 await self._topology.on_change(
231 self._server_description,
232 reset_pool=self._server_description.error,
233 interrupt_connections=isinstance(self._server_description.error, NetworkTimeout),
234 )
235
236 if self._stream and (
237 self._server_description.is_server_type_known
238 and self._server_description.topology_version
239 ):
240 await self._start_rtt_monitor()
241 # Immediately check for the next streaming response.
242 self._executor.skip_sleep()
243
244 if self._server_description.error and prev_sd.is_server_type_known:
245 # Immediately retry on network errors.
246 self._executor.skip_sleep()
247 except ReferenceError:
248 # Topology was garbage-collected.
249 await self.close()
250 finally:
251 if self._executor._stopped:
252 await self._rtt_monitor.close()
253
254 async def _check_server(self) -> ServerDescription:
255 """Call hello or read the next streaming response.

Callers 1

targetMethod · 0.45

Calls 7

_check_serverMethod · 0.95
_start_rtt_monitorMethod · 0.95
closeMethod · 0.95
ServerDescriptionClass · 0.90
_sanitizeFunction · 0.70
skip_sleepMethod · 0.45
on_changeMethod · 0.45

Tested by

no test coverage detected