question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve error message [was: Cannot hash a function with `sys.stderr` in the body]

See original GitHub issue

Summary

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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
wjaskowskicommented, Jan 4, 2021

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 😃

0reactions
tconklingcommented, Nov 14, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found