MCPcopy
hub / github.com/celery/celery / _close_database

Method _close_database

celery/fixups/django.py:219–240  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

217 return "prefork" in pool
218
219 def _close_database(self) -> None:
220 try:
221 connections = self._db.connections.all(initialized_only=True)
222 except TypeError:
223 # Support Django < 4.1
224 connections = self._db.connections.all()
225
226 is_prefork = self._is_prefork()
227
228 for conn in connections:
229 try:
230 conn.close()
231 pool_enabled = self._settings.DATABASES.get(conn.alias, {}).get("OPTIONS", {}).get("pool")
232 if pool_enabled and is_prefork and hasattr(conn, "close_pool"):
233 with contextlib.suppress(KeyError):
234 conn.close_pool()
235 except self.interface_errors:
236 pass
237 except self.DatabaseError as exc:
238 str_exc = str(exc)
239 if 'closed' not in str_exc and 'not connected' not in str_exc:
240 raise
241
242 def close_cache(self) -> None:
243 try:

Callers 4

close_databaseMethod · 0.95
test__close_databaseMethod · 0.80

Calls 3

_is_preforkMethod · 0.95
closeMethod · 0.45
getMethod · 0.45

Tested by 2

test__close_databaseMethod · 0.64