Streamlit Recursion

Hello

I understand that streamlit rerun script from top-to-bottom. I am using python and after running the streamlit web app for awhile it will throw the Recursion Error: maximum recursion depth exceeded while calling a Python object error. I also understand that I could actually increase python’s recursion limit however it is not advisable. Does the rerun every time causes the recursion error? how can i avoid this recursion error? Please help:)

import streamlit as st

selected_flavour = None
selected_sugar = None

selected_tea = st.radio(“Type of Tea:”, (‘Black Tea’, ‘Red Tea’, ‘Green Tea’, ‘Oolong Tea’))
if selected_tea == ‘Black Tea’:
selected_flavour = st.selectbox( ‘Flavour:’, (‘Grapefruit’, ‘Honey’))
selected_sugar = st.selectbox( ‘Sugar Level:’, (‘50%’, ‘100%’))

if selected_tea == ‘Red Tea’:
selected_flavour = st.selectbox( ‘Flavour:’, (‘Lychee’, ‘Orange’))
selected_sugar = st.selectbox( ‘Sugar Level:’, (‘50%’, ‘100%’))

if selected_tea == ‘Green Tea’:
selected_flavour = st.selectbox( ‘Flavour:’, (‘Lemon’, ‘Melon’))
selected_sugar = st.selectbox( ‘Sugar Level:’, (25%, ‘50%’, ‘100%’))

if selected_tea == ‘Oolong Tea’:
selected_flavour = st.selectbox( ‘Flavour:’, (‘Honey’, ‘Pineapple’))
selected_sugar = st.selectbox( ‘Sugar Level:’, (0%, ‘50%’, ‘100%’))

order=st.button(“Order”)

if order:
t= threading.Thread(target=place_order, args=[selected_tea, selected_flavour, selected_sugar])
t.start()

#display orders
place_order(selected_tea, selected_flavour, selected_sugar)
st.experimental_rerun()

def place_order(selected_tea,
selected_flavour, selected_sugar ):
list = add_to_list(selected_tea, selected_flavour, selected_sugar)
order_id, order_time, order_collected= >st.columns([1, 1, 1])
for id, drink in enumerate(list, start=0):
with order_id:
order_id.text(drink.name)
with order_time:
order_time(drink.time)
with order_collected:
order_collected.button(“collect”)

Thanks

Hi @qt.qt, could you share a minimal code snippet which produces this behavior? See this post for more details.

The answer in very generic terms is that streamlit does not typically cause recursion errors, and it’s most likely some unintentional recursion in your app’s code. But it’s hard to be more helpful than that without a minimal reproducible code sample.

i have included some code snippets.

1 Like

The exception must come from the place_order function, though it’s not defined in the snippet. When an exception is raised, it comes with a traceback which helps to determine where exactly the code fails.

2 Likes