How to avoid multiple print/log messages in console

Hello,

I’m running locally streamlit==1.30.0 on python==3.11.5.

My Home.py, for what concerns this topic, can be reduced to the following configuration:

import streamlit as st
from page_init import page_init

def page_script():
    st.write("This is Home.py")
    print("This is a test Home.py print message")

page_init(page_script)

With page_init function defined as:

import streamlit as st

def page_init(page_script):
    st.write("This is page_init.py")
    print("This is a test page_init.py print message")
    page_script()

If I run the app: streamlit run Home.py
What I can see in the browser is the result I’m expecting, that is the two messages:

This is page_init.py
This is Home.py

However, in the console I find multiple print statements:

  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8501
  Network URL: http://10.66.87.163:8501

This is a test page_init.py print message
This is a test Home.py print message
This is a test page_init.py print message
This is a test Home.py print message
This is a test page_init.py print message
This is a test Home.py print message
This is a test page_init.py print message
This is a test Home.py print message
This is a test page_init.py print message
This is a test Home.py print message
This is a test page_init.py print message
This is a test Home.py print message

This is especially annoying using the logging module instead of print statements, because I get multiple log statements in stdout for the same log message. I can’t figure out how to avoid this behaviour.

Any help will be very much appreciated.

Thank you!