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)
| 610 | |
| 611 | |
| 612 | def 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 | |
| 635 | def safe_upload_path(filename: str, base_dir) -> str: |
no test coverage detected