Python Glossary Русский

Python 3.7+gcfunction

gc.freeze()

collection control

Moves all tracked objects into a 'permanent' generation that the collector no longer walks. Meant for use before fork.

Syntax

gc.freeze()

The goal is saving memory on fork without exec: walking objects, the collector writes to their headers, and copy-on-write copies those pages in every child. The documented recipe: gc.disable() early in the parent, gc.freeze() right before fork, gc.enable() in the child. Frozen cycles are never freed until gc.unfreeze — in an ordinary program that is a leak, not a speed-up.

Examples

import gc
gc.freeze()
print(gc.get_freeze_count() > 0)  # → True
print(gc.get_freeze_count())  # → ? сколько объектов заморожено
gc.unfreeze()
print(gc.get_freeze_count())  # → 0

See also

Open in the full glossarydocs.python.orgReport an inaccuracy