Session State seems to time out

I am running a streamlit app locally that functions great when first deployed. But, after about 15-20 minutes I get the following error:

DatabaseError: Invalid SessionHandle: SessionHandle [9cbe6820-6e33-4176-8561-026d6b1f4f3f]

Traceback:

File "C:\PyCharmProjects\MODTaskCapacityTable\venv\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 535, in _run_script
    exec(code, module.__dict__)File "C:\PyCharmProjects\MODTaskCapacityTable\Main.py", line 89, in <module>
    mDFfunc = modTask(stc0,date_time)File "C:\PyCharmProjects\MODTaskCapacityTable\functions.py", line 85, in modTask
    editDF = stc0.data_editor(pullRawData(mTask),File "C:\PyCharmProjects\MODTaskCapacityTable\db_data.py", line 39, in pullRawData
    cursor.execute(mQuery)File "C:\PyCharmProjects\MODTaskCapacityTable\venv\lib\site-packages\databricks\sql\client.py", line 472, in execute
    execute_response = self.thrift_backend.execute_command(File "C:\PyCharmProjects\MODTaskCapacityTable\venv\lib\site-packages\databricks\sql\thrift_backend.py", line 832, in execute_command
    resp = self.make_request(self._client.ExecuteStatement, req)File "C:\PyCharmProjects\MODTaskCapacityTable\venv\lib\site-packages\databricks\sql\thrift_backend.py", line 388, in make_request
    ThriftBackend._check_response_for_error(response)File "C:\PyCharmProjects\MODTaskCapacityTable\venv\lib\site-packages\databricks\sql\thrift_backend.py", line 206, in _check_response_for_error
    raise DatabaseError(response.status.errorMessage)

I have tried messing with the cashes and session states, but nothing seems to help. Any ideas? Thank you

Hi @byarsmc79

It seems that the error may arise from the Database connection. Could you check this and see if there are parameters that you can adjust.

For example, you may try adjusting the ttl parameter of st.connection (st.connection - Streamlit Docs).

Hope this helps!

Actually, that pointed me in the right direction! I had moved my various DB calls into their own functions, but left the actual connection outside of those functions. So the initial connection was timing out. I wrapped the connection into a function and call it within the other functions and that appears to have solved the issue. I didn’t catch that it was a DB issue until you pointed it out. Thanks.

1 Like

Glad to hear that it’s working now and thanks for sharing the specifics, Happy Streamlit-ing!

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