all Python 3gcfunction
gc.isenabled()
collection control
Returns True if automatic collection of cyclic garbage is enabled.
Syntax
gc.isenabled()
It lets you restore state correctly: 'turn it off for a while' means remember isenabled(), disable, and in finally re-enable only if it was enabled. Otherwise your code turns on a collector the caller had turned off. The answer says nothing about manual gc.collect calls — they work even with automation off.
Examples
import gc
was = gc.isenabled()
gc.disable()
try:
print(gc.isenabled()) # → False
finally:
if was:
gc.enable()
print(gc.isenabled()) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy