How do I find what is using memory in a Python process in a production system?
Using Python’s gc garbage collector interface and sys.getsizeof() it’s possible to dump all the python objects and their sizes. Here’s the code I’m using in production to troubleshoot a memory leak: rss = psutil.Process(os.getpid()).get_memory_info().rss # Dump variables if using more than 100MB of memory if rss > 100 * 1024 * 1024: memory_dump() os.abort() def … Read more