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.