File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,6 +35,22 @@ The :mod:`!gc` module provides the following functions:
3535 Return ``True `` if automatic collection is enabled.
3636
3737
38+ .. function :: ensure_disabled()
39+
40+ Return a context manager that temporarily disables the garbage
41+ collector. The collector is disabled at the start of the ``with ``
42+ block and restored to its previous state on exit::
43+
44+ with gc.ensure_disabled():
45+ ... # GC is disabled during this block
46+
47+ Nesting is supported — each level saves and restores its own state.
48+ If the collector was already disabled before entering the block, it
49+ remains disabled after exit.
50+
51+ .. versionadded :: 3.16
52+
53+
3854.. function :: collect(generation=2)
3955
4056 With no arguments, run a full collection. The optional argument *generation *
Original file line number Diff line number Diff line change 1+ Add :func: `gc.ensure_disabled ` context manager to temporarily disable
2+ the garbage collector. By Saksham Kapoor in :issue: `75537 `.
You can’t perform that action at this time.
0 commit comments