'How to use memray with Gunicorn and Django?

I have a project with Django and I did a multiread with Gunicorn. but my project has a memory leak. I want to monitor memory with "memray" but I don't know how to use "memray".



Solution 1:[1]

During local development, I've had success by running:

python -m memray run manage.py runserver 0:8000 --nothreading

I haven't had memray running in production yet, but memray's documentation does mention --follow-fork may be useful when using Gunicorn.

Memray can optionally continue tracking in a child process after a parent process forks. This can be useful when using multiprocessing, or a framework utilizing a pre-fork pattern like Celery or Gunicorn.

https://bloomberg.github.io/memray/run.html#tracking-across-forks

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aaron