# Streamlit Recursion

**URL:** <https://discuss.streamlit.io/t/streamlit-recursion/31076>\
**Category:** Using Streamlit\
**Created:** [September 23, 2022, 2:53pm UTC](https://discuss.streamlit.io/t/streamlit-recursion/31076 "2022-09-23T14:53:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![qt.qt](https://avatars.discourse-cdn.com/v4/letter/q/ba9def/32.png) [@qt.qt](https://discuss.streamlit.io/u/qt.qt)\
**Post date:** [September 23, 2022, 2:53pm UTC](https://discuss.streamlit.io/t/streamlit-recursion/31076/1 "2022-09-23T14:53:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![blackary](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/blackary/32/47725_2.png) [@blackary](https://discuss.streamlit.io/u/blackary)\
**Post date:** [September 23, 2022, 4:04pm UTC](https://discuss.streamlit.io/t/streamlit-recursion/31076/2 "2022-09-23T16:04:11Z")

</div>

Hi @qt.qt, could you share a minimal code snippet which produces this behavior? See [this post](https://discuss.streamlit.io/t/how-to-post-a-question-in-the-streamlit-forum/30960) 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.

---

<div class="post-metadata">

**Author:** ![qt.qt](https://avatars.discourse-cdn.com/v4/letter/q/ba9def/32.png) [@qt.qt](https://discuss.streamlit.io/u/qt.qt)\
**Post date:** [September 24, 2022, 8:48am UTC](https://discuss.streamlit.io/t/streamlit-recursion/31076/3 "2022-09-24T08:48:16Z")

</div>

i have included some code snippets.

---

<div class="post-metadata">

**Author:** ![edsaac](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/edsaac/32/47599_2.png) [@edsaac](https://discuss.streamlit.io/u/edsaac)\
**Post date:** [September 25, 2022, 3:14pm UTC](https://discuss.streamlit.io/t/streamlit-recursion/31076/4 "2022-09-25T15:14:13Z")

</div>

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.

> **[Understanding the Python Traceback – Real Python](https://realpython.com/python-traceback/#how-do-you-read-a-python-traceback)**
>
> In this step-by-step tutorial, you'll learn how to read and understand the information you can get from a Python traceback. You'll walk through several examples of tracebacks and see some of the most common tracebacks in Python.

---

<div class="post-metadata">

**Author:** ![HHest](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/hhest/32/46544_2.png) [@HHest](https://discuss.streamlit.io/u/HHest)\
**Post date:** [January 24, 2023, 11:29am UTC](https://discuss.streamlit.io/t/streamlit-recursion/31076/5 "2023-01-24T11:29:25Z")

</div>

You might be suffering from the issue described here [maximum recursion depth exceeded · Issue #3094 · streamlit/streamlit (github.com)](https://github.com/streamlit/streamlit/issues/3094). Pretty much st.experimental\_rerun is not designed to support an infinite rerun loop according to @kmcgrady.

Not sure why this limitation is there, but I would love it to be lifted. Like you, I am trying to write an app that would consume some incoming data stream.

Some people have suggested using asyncio, but unfortunately input widgets do not work with this technique.

… Ah! I just noticed that @kmcgrady has written an autorefresh component [Streamlit Autorefresh - 🧩 Streamlit Components - Streamlit](https://discuss.streamlit.io/t/streamlit-autorefresh/14519). Perhaps this would help us avoid the RecursionError.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [January 24, 2024, 11:29am UTC](https://discuss.streamlit.io/t/streamlit-recursion/31076/6 "2024-01-24T11:29:51Z")

</div>

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
