Too many open file error

I am running a streamlit app (version 1.11.1) on AWS EC2 ubuntu server. In the app, users upload a csv file and visualize the data. Users frequently change different csv files (e.g., 100 per day) from different dataset to do check the visualization. After the app runs for a few days, I got the following error and I have to reboot the app to get back to normal. After googling the web and some solutions suggest to change the ulimit to a larger number for a temporary solution.

I think there maybe a solution by closing the files in the st.file_uploader function. That is, it should also close the file (descriptor) at some point (this page Where does st.file_uploader store uploaded files and when do they get deleted? - Streamlit Docs indicates it will delete the file from RAM, but not sure if it close the file). Or it is already there and I just did not notice? Any thoughts? Thanks a lot.


OSError: [Errno 24] Too many open files
Aug 02 11:56:06 bash[44354]: 2022-08-02 11:56:06.669 Exception in callback BaseAsyncIOLoop._handle_events(10, 1)
Aug 02 11:56:06 bash[44354]: handle: <Handle BaseAsyncIOLoop._handle_events(10, 1)>
Aug 02 11:56:06 bash[44354]: Traceback (most recent call last):
Aug 02 11:56:06 bash[44354]: File “/usr/lib/python3.8/asyncio/events.py”, line 81, in _run
Aug 02 11:56:06 bash[44354]: File “/home/ubuntu/smlit/lib/python3.8/site-packages/tornado/platform/asyncio.py”, line 189, in _handle_events
Aug 02 11:56:06 bash[44354]: File “/home/ubuntu/smlit/lib/python3.8/site-packages/tornado/netutil.py”, line 266, in accept_handler
Aug 02 11:56:06 bash[44354]: File “/usr/lib/python3.8/socket.py”, line 292, in accept