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

Method open

pymongo/asynchronous/topology.py:218–255  ·  view source on GitHub ↗

Start monitoring, or restart after a fork. No effect if called multiple times. .. warning:: Topology is shared among multiple threads and is protected by mutual exclusion. Using Topology from a process other than the one that initialized it will emit a warning a

(self)

Source from the content-addressed store, hash-verified

216 self._monitor_tasks: list[MonitorBase] = []
217
218 async def open(self) -> None:
219 """Start monitoring, or restart after a fork.
220
221 No effect if called multiple times.
222
223 .. warning:: Topology is shared among multiple threads and is protected
224 by mutual exclusion. Using Topology from a process other than the one
225 that initialized it will emit a warning and may result in deadlock. To
226 prevent this from happening, AsyncMongoClient must be created after any
227 forking.
228
229 """
230 pid = os.getpid()
231 if self._pid is None:
232 self._pid = pid
233 elif pid != self._pid:
234 self._pid = pid
235 if sys.version_info[:2] >= (3, 12):
236 kwargs = {"skip_file_prefixes": (_pymongo_dir,)}
237 else:
238 kwargs = {"stacklevel": 6}
239 # Ignore B028 warning for missing stacklevel.
240 warnings.warn( # type: ignore[call-overload] # noqa: B028
241 "AsyncMongoClient opened before fork. May not be entirely fork-safe, "
242 "proceed with caution. See PyMongo's documentation for details: "
243 "https://dochub.mongodb.org/core/pymongo-fork-deadlock",
244 **kwargs,
245 )
246 async with self._lock:
247 # Close servers and clear the pools.
248 for server in self._servers.values():
249 await server.close()
250 # Reset the session pool to avoid duplicate sessions in
251 # the child process.
252 self._session_pool.reset()
253
254 async with self._lock:
255 await self._ensure_opened()
256
257 def get_server_selection_timeout(self) -> float:
258 # CSOT: use remaining timeout when set.

Callers 1

_ensure_openedMethod · 0.45

Calls 4

_ensure_openedMethod · 0.95
valuesMethod · 0.80
closeMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected