Python Detect Memory Usage of Current Program

Oct 8, 2019
pip install psutil
import psutilimport logginglog = ...def print_memory_usage(message):    # return the memory usage in percentage like top    process = psutil.Process(os.getpid())    # mem = process.memory_percent()    memory = int(process.memory_info().rss / 1_000_000)    log.info(f"{message}, Memory={memory}MB")print_memory_usage('start')

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.