Improve error message [was: Cannot hash a function with `sys.stderr` in the body]
See original GitHub issueSummary
When a function has print('sth', file=sys.stderr)
in the body I get:
InternalHashError: [Errno 2] No such file or directory: '<stderr>'
While caching the body of eval_models_on_all_data(), Streamlit encountered an object of type _io.TextIOWrapper, which it does not know how to hash.
Steps to reproduce
Code snippet:
@st.cache
def f():
print('', file=sys.stderr)
Debug info
- Streamlit, version 0.73.1
- Python 3.7.9
- Linux roo 5.8.0-33-generic #36-Ubuntu SMP Wed Dec 9 09:14:40 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Python sys.stderr flush frequency - buffer - Stack Overflow
On Python 2, I can't find where in the documentation sys.stderr 's buffering ... The standard error stream is not fully buffered in...
Read more >Error handling in R with tryCatchLog: Catching, logging, post ...
The main advantages of the tryCatchLog function over tryCatch are: Easy logging of errors, warnings and messages into a file or console ...
Read more >Build a Hash Table in Python With TDD
The hash() function will raise an exception if you try calling it against ... and display the message on the standard error stream...
Read more >2 Server Error Message Reference - MySQL :: Developer Zone
Message : Can't read record in system table. Returned by InnoDB for attempts to access InnoDB INFORMATION_SCHEMA tables when InnoDB is unavailable. Error...
Read more >Caching issues - Streamlit Docs
While developing an app, if you see an error or warning that stems from a cached function, it's probably related to the hashing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is fine. I understand - I cannot hash anything with side-effects. I just had some error logging inside the function. Sure, I could refactor that to move the logging outside it. However, I raised this issue since: 1) The error message was not clear to me and I struggled to understand that the sys.stderr is to blame. 2) The error message itself explicitly stated that this might be a bug in streamlit and I should raise an issue 😃
Closing this because our new caching primitives,
@st.experimental_memo
and@st.experimental_singleton
, don’t have this issue (because they don’t attempt to hash all the symbols inside the cached function). New code should prefer memo/singleton over@st.cache
.