Created
April 7, 2021 15:47
-
-
Save Klemek/9e14724500a3d6cabc839ecb9fc80b7f to your computer and use it in GitHub Desktop.
memory debug for python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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