Skip to content

Commit

Permalink
xgc: Support nested gc_disabled() contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfstr committed Sep 8, 2023
1 parent 48731b4 commit 1afd5fa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/crystal/util/xgc.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ def gc_disabled() -> Iterator[None]:
Useful when allocating a very large number of long-lived objects,
to avoid many useless runs of the garbage collector.
"""
assert gc.isenabled()
gc.disable()
was_enabled = gc.isenabled()
if was_enabled:
gc.disable()
try:
yield
finally:
assert not gc.isenabled()
gc.enable()
if was_enabled:
gc.enable()

0 comments on commit 1afd5fa

Please sign in to comment.