RuntimeError: generator didn't stop

Hi there,

so my app was working normally but then (without me changing anything) I suddenly get these strange Runtime Errors that I’ve never seen before (see below). Every few seconds, this error gets written in the log again.

Does anyone know what this is?

Exception in callback _HandlerDelegate.execute.<locals>.<lambda>(<Task finishe...didn't stop")>) at /home/appuser/venv/lib/python3.11/site-packages/tornado/web.py:2434
handle: <Handle _HandlerDelegate.execute.<locals>.<lambda>(<Task finishe...didn't stop")>) at /home/appuser/venv/lib/python3.11/site-packages/tornado/web.py:2434>
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/appuser/venv/lib/python3.11/site-packages/tornado/web.py", line 2434, in <lambda>
    fut.add_done_callback(lambda f: f.result())
                                    ^^^^^^^^^^
  File "/home/appuser/venv/lib/python3.11/site-packages/sentry_sdk/integrations/tornado.py", line 75, in sentry_execute_request_handler
    with _handle_request_impl(self):
  File "/usr/local/lib/python3.11/contextlib.py", line 148, in __exit__
    raise RuntimeError("generator didn't stop")
RuntimeError: generator didn't stop
Exception in callback _HandlerDelegate.execute.<locals>.<lambda>(<Task finishe...didn't stop")>) at /home/appuser/venv/lib/python3.11/site-packages/tornado/web.py:2434
handle: <Handle _HandlerDelegate.execute.<locals>.<lambda>(<Task finishe...didn't stop")>) at /home/appuser/venv/lib/python3.11/site-packages/tornado/web.py:2434>
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/appuser/venv/lib/python3.11/site-packages/tornado/web.py", line 2434, in <lambda>
    fut.add_done_callback(lambda f: f.result())
                                    ^^^^^^^^^^
  File "/home/appuser/venv/lib/python3.11/site-packages/sentry_sdk/integrations/tornado.py", line 75, in sentry_execute_request_handler
    with _handle_request_impl(self):
  File "/usr/local/lib/python3.11/contextlib.py", line 148, in __exit__
    raise RuntimeError("generator didn't stop")
RuntimeError: generator didn't stop

@lasinludwig with help from ChatGPT debugging →

Option 1: it seems to be related to the Tornado web framework. The error occurs when a callback function is executed, but the generator it is part of does not stop properly, leading to a RuntimeError with the message “generator didn’t stop.”

Please debug use of the yield statement in your code.

Review the code and make sure that any generators used in that function are correctly structured and that they terminate appropriately.

Option 2: Compatibility issues, Did you upgrade any version of Python or Tornado? Without seeing your code hard to debug. Can you check your versions and try to downgrade Python or Tornado?

Hi @tonyhollaar ,thanks for your reply!

I don’t know what the Tornado web framework is. I’m guessing it’s some dependency - I’m not using it directly.

I tried all sorts of stuff and I’m still not sure what the actual problem was, but (at least for now) I “fixed” it by removing all @st.cache_data decorators from my code.

As I’m in the middle of rewriting a lot of my code, this works fine as a temporary fix so people can use my app until I get the big update done. :+1:

Glad to hear @lasinludwig that you found the issue! happy streamlitting…