Hi everyone,
I am currently working on a app that saves that saves a file for the current user session. I want to clean up this file once the session is inactive.
Is there a way to retrieve all active session ids? Or to trigger a function before a session becomes inactive?
The code basically looks like this:
#Fist step: get the current session id:
from streamlit.runtime.scriptrunner.script_run_context import get_script_run_ctx
ctx = get_script_run_ctx()
session_id = ctx.id
#Second step: save a file
image_as_bytes = "random_bytes_that_make_up_an_image"
path_to_image = f"random_path/{session_id}.png"
with open(path_to_image,"wb") as file:
file.write(image_as_bytes)
#Third Step: Delete Images from inactive Sessions
#tbd.
Thank you very much for your help & ideas.
Best regards
Fabian