Skip to content

Instantly share code, notes, and snippets.

@Klemek
Created April 7, 2021 15:47
Show Gist options
  • Save Klemek/9e14724500a3d6cabc839ecb9fc80b7f to your computer and use it in GitHub Desktop.
Save Klemek/9e14724500a3d6cabc839ecb9fc80b7f to your computer and use it in GitHub Desktop.
memory debug for python
import os
import psutil # pip install psutil
import logging
import asyncio
process = psutil.Process(os.getpid())
async def watch_memory():
last_mem = 0
while True:
mem = process.memory_info().rss
if mem != last_mem:
logging.info(f"{mem:,} B")
last_mem = mem
await asyncio.sleep(0.1)
asyncio.run_coroutine_threadsafe(watch_memory(), asyncio.get_event_loop())
# import memory_watcher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment