Hi there! I have a multipage streamlit app and a separate python script for resource monitoring and writing a log. The main file looks something like this.
if __name__ == "__main__":
monitor_thread = threading.Thread(target=resource_monitor)
monitor_thread.daemon = True
monitor_thread.start()
main()
main()
contains all the streamlit code for the homepage. Now, the resource monitor works fine. It’s able to track the resource usage of the python process all throughout the app’s execution. My issue lies with the part where a log file containing max cpu and ram usage % is written.
My app has 4 pages: home, 1, 2, and 3. If I stop the script at pages home and 1, the log gets written successfully. This isn’t the case for pages 2 and 3. This is how my code for the log-writing looks like.
import atexit
def resource_monitor():
*some tqdm code here*
atexit.register(write_log)
write_log
contains the writing to file part in this code. I’d like to know if using atexit in the context of a streamlit app is problematic, and if there is a better way to get resource monitoring stats for an app ran locally.