INNER CODE UNIT · Python

_tuned_gc

koxudaxi/datamodel-code-generator · src/datamodel_code_generator/__init__.py:161

def _tuned_gc() -> Iterator[None]:
    """Raise the young-generation GC threshold while one generation run is in progress.

    Process-global by nature: only the outermost concurrent caller changes and restores the
    threshold, nested or parallel calls are counted, and a host that disabled GC is left alone.
    """
    global _gc_saved_threshold  # noqa: PLW0603

    with _gc_tuning_lock:
        match _gc_tuning_depth[0]:
            case 0 if gc.isenabled():
                _gc_saved_threshold = gc.get_threshold()
                gc.set_threshold(_GC_YOUNG_THRESHOLD, *_gc_saved_threshold[1:])
                _gc_tuning_depth[0] = 1
            case 0:
                # Negative depth records scopes entered while the host disabled GC.
                _gc_tuning_depth[0] = -1
            case depth:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…