MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / spawn_memory_trim

Function spawn_memory_trim

core/utils.py:612–632  ·  view source on GitHub ↗

Reclaim a request's heap pages: GC, then return freed C pages to the OS. On gevent uWSGI workers the trim runs in a spawned greenlet so it never blocks the caller; Celery prefork workers (no gevent hub) run it inline. Set close_connections=True when called from a streaming generator's t

(close_connections=False)

Source from the content-addressed store, hash-verified

610
611
612def spawn_memory_trim(close_connections=False):
613 """Reclaim a request's heap pages: GC, then return freed C pages to the OS.
614
615 On gevent uWSGI workers the trim runs in a spawned greenlet so it never
616 blocks the caller; Celery prefork workers (no gevent hub) run it inline.
617 Set close_connections=True when called from a streaming generator's teardown
618 so the pooled DB connection is released first.
619 """
620 def _run():
621 cleanup_memory(force_collection=True)
622 trim_c_allocator_heap()
623
624 if close_connections:
625 from django.db import close_old_connections
626 close_old_connections()
627
628 if _is_gevent_monkey_patched():
629 import gevent
630 gevent.spawn(_run)
631 else:
632 _run()
633
634
635def safe_upload_path(filename: str, base_dir) -> str:

Callers 1

_epg_export_teardownFunction · 0.90

Calls 2

_runFunction · 0.85

Tested by

no test coverage detected