Error: AssertionError: This function must only be called on the main thread

I’m not sure what is happening. I’m getting an AssertionError when calling streamlit run main.py

My script basically connects to Snowflake, queries tables into Pandas dataframes, and then calls st.write(df). I’ve also tried st.table(df).

Logs:

2022-08-23 11:39:11.567 Exception in callback AppSession._on_scriptrunner_event.<locals>.<lambda>() at c:\users\michael kleban\appdata\local\programs\python\python39\lib\site-packages\streamlit\runtime\app_session.py:400
handle: <Handle AppSession._on_scriptrunner_event.<locals>.<lambda>() at c:\users\michael kleban\appdata\local\programs\python\python39\lib\site-packages\streamlit\runtime\app_session.py:400>
Traceback (most recent call last):
  File "c:\users\michael kleban\appdata\local\programs\python\python39\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "c:\users\michael kleban\appdata\local\programs\python\python39\lib\site-packages\streamlit\runtime\app_session.py", line 400, in <lambda>
    lambda: self._handle_scriptrunner_event_on_main_thread(
  File "c:\users\michael kleban\appdata\local\programs\python\python39\lib\site-packages\streamlit\runtime\app_session.py", line 400, in <lambda>    lambda: self._handle_scriptrunner_event_on_main_thread(
  File "c:\users\michael kleban\appdata\local\programs\python\python39\lib\site-packages\streamlit\runtime\app_session.py", line 445, in _handle_scriptrunner_event_on_main_thread
    assert (AssertionError: This function must only be called on the main thread
2022-08-23 11:39:11.570 Exception in callback AppSession._on_scriptrunner_event.<locals>.<lambda>() at c:\users\michael kleban\appdata\local\programs\python\python39\lib\site-packages\streamlit\runtime\app_session.py:400
handle: <Handle AppSession._on_scriptrunner_event.<locals>.<lambda>() at c:\users\michael kleban\appdata\local\programs\python\python39\lib\site-packages\streamlit\runtime\app_session.py:400>
Traceback (most recent call last):
  File "c:\users\michael kleban\appdata\local\programs\python\python39\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "c:\users\michael kleban\appdata\local\programs\python\python39\lib\site-packages\streamlit\runtime\app_session.py", line 400, in <lambda>    lambda: self._handle_scriptrunner_event_on_main_thread(
  File "c:\users\michael kleban\appdata\local\programs\python\python39\lib\site-packages\streamlit\runtime\app_session.py", line 445, in _handle_scriptrunner_event_on_main_thread
    assert (AssertionError: This function must only be called on the main thread

Hi @Michael_Kleban,

Thanks for posting!

Can you share a link to your code, with any sensitive data/credentials removed?

Caroline :balloon:

Hi @Caroline

Thanks for responding! I actually found the culprit. It was from an eventlet method being called before the script connects to snowflake. It was an outdated line copied from a script that our former DE wrote. I removed it and everything works!

Thanks,
Michael

1 Like

Awesome, thanks for sharing that! Glad it’s working

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