Skip to content

Commit 83d9729

Browse files
Add doc and NEWS for gc.ensure_disabled()
1 parent b527c01 commit 83d9729

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

Doc/library/gc.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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*
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add :func:`gc.ensure_disabled` context manager to temporarily disable
2+
the garbage collector. By Saksham Kapoor in :issue:`75537`.

0 commit comments

Comments
 (0)