-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Checklist
- I have searched the existing issues for similar feature requests.
- I added a descriptive title and summary to this issue.
Summary
If you use deferred download with st.download_button, there should be a way to catch errors that may be raised by the deferred generation function. Currently, if the funciton encounters an error, a warning message is displayed on the frontend and isn't accessible on the backend.
Why?
When you use deferred download with st.download_button, the function which returns the download runs on its own thread so it won't block the script thread. This has two consequences:
- There is no script context, so you can't use any Streamlit command, like
st.session_state. (See Access Session State inst.download_buttoncallable #13337). - You can't handle errors raised by the deferred download function.
You can put try-catch blocks in your download function to avoid an unhandled error, but you can't really do anything about it because you can't display a custom message or log something in Session State. (Maybe you could hack a solution by writing something to a temporary file on the server, but that doesn't seem ideal.)
How?
A couple different solutions:
- Have the download button return an error if encountered so it can be caught in the main script.
- Give the download thread some (possibly restricted) script context (like Access Session State in
st.download_buttoncallable #13337). - Improve multithreading support more generally, and have some hook at the end of a script run to catch a session's child threads, like the download thread.
Additional Context
No response