Managing /tmp files when there are multiple users using the app at the same time

What is the best way to handle temporary files for a given user’s session when there are multiple users using the app at the same time?

For instance if I have a user that wants to classify an image they upload, how and where should it be stored? I’m currently using a /tmp/ directory, but it is cleared upon app load. But if I have multiple users visiting the app at the same time, then one user’s tmp might be cleared by another user’s app load.

Am I misunderstanding anything? Am I handing this functionality in a completely wrong way? Any help is appreciated :slight_smile:

Hey @zacheism - there’s currently nothing in the public Streamlit API that can distinguish between multiple “user sessions”.

However! See this thread and associated Gist where @thiago demonstrates a method for creating a session ID.

If you don’t mind the hackiness, you could use the code from the Gist to create your user-specific temp files at e.g. "/tmp/%s" % get_session_id().

1 Like

@zacheism It might not make sense for your application. But I want to be able to save and resume sessions, so I’m currently asking the user to supply a short label that I use as a directory to store the contents of their session.