Gracefully handle memory limit quotas

Hi team!

I would like to ask if there is any way to gracefully handle app resource quotas, especially memory limits. I understand that RAM is capped at 2.7GB and terminates the app if it is exceeded.

Is there a way to catch this so that I do not need to reboot my application everytime it exceeds the quota?

For context, my application is largely dependent on user input links to audio files and processing them consumes RAM. I have managed reduce from 3GB to <800MB for 1 hour audio file.

I have tried setting memory limits in my application:

from app import run
import streamlit as st
import asyncio
import resource

if __name__ == "__main__":
    fixed_memory = 2 * 1024**3  # Streamlit limit 
    # Calculate 98% of the fixed memory value
    memory_limit = int(fixed_memory * 0.98)
    # Set the memory limit
    resource.setrlimit(resource.RLIMIT_AS, (memory_limit, memory_limit))
    
    st.set_page_config(
        page_title="CrateDigger",
        page_icon="🐡",
    )

    asyncio.run(run())

And

ValueError: not allowed to raise maximum limit

Seeking advice if this is possible! Otherwise, I can arbitrarily set duration limit for audio file too.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.