Cannot print the terminal output in Streamlit?

For streamlit 1.16.0, it works wtih:

from streamlit.runtime.scriptrunner.script_run_context import SCRIPT_RUN_CONTEXT_ATTR_NAME
...
if getattr(current_thread(), SCRIPT_RUN_CONTEXT_ATTR_NAME, None):