Python Glossary Русский

Python 3.7+gcfunction

gc.get_freeze_count()

collection control

Returns the number of objects in the permanent generation where gc.freeze put them.

Syntax

gc.get_freeze_count()

Useful to verify that freezing really happened before fork and that it was undone later. Do not expect zero at startup: Python 3.12 reports a few hundred permanent objects right after launch. The number depends on the version and on imported modules, so tests check 'greater than zero' after freeze and zero after unfreeze, not a constant.

Examples

import gc
print(gc.get_freeze_count())  # → ? 0, а на 3.12 — сотни уже при старте
gc.freeze()
print(gc.get_freeze_count() > 0)  # → True
gc.unfreeze()
print(gc.get_freeze_count())  # → 0

See also

Open in the full glossarydocs.python.orgReport an inaccuracy