Streamlit RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'


I ran my code using anaconda and it actually opened the browser and just showed “please wait” and said " [TypeError: Protocols cannot be instantiated" . Then I updated my python from 3.9.7 to 3.9.12. And the browser showed “RuntimeError: There is no current event loop in thread ‘ScriptRunner.scriptThread’.”

Steps to reproduce

Code snippet:


2022-10-26 13:22:20.427 INFO    numexpr.utils: Note: NumExpr detected 16 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 8.
2022-10-26 13:22:20.427 INFO    numexpr.utils: NumExpr defaulting to 8 threads.
2022-10-26 13:22:21.868 
  Warning: to view this Streamlit app on a browser, run it with the following

    streamlit run D:\Users\admin\anaconda3\envs\py34\lib\site-packages\ [ARGUMENTS]


RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'.
File "D:\Users\admin\anaconda3\envs\py34\lib\site-packages\streamlit\runtime\scriptrunner\", line 562, in _run_script
    exec(code, module.__dict__)
File "D:\Users\admin\anaconda3\envs\py34\Lib\site-packages\", line 17, in <module>
File "D:\Users\admin\anaconda3\envs\py34\lib\site-packages\traitlets\config\", line 845, in launch_instance
File "D:\Users\admin\anaconda3\envs\py34\lib\site-packages\traitlets\config\", line 88, in inner
    return method(app, *args, **kwargs)
File "D:\Users\admin\anaconda3\envs\py34\lib\site-packages\ipykernel\", line 681, in initialize
File "D:\Users\admin\anaconda3\envs\py34\lib\site-packages\ipykernel\", line 522, in init_kernel
    shell_stream = ZMQStream(self.shell_socket)
File "D:\Users\admin\anaconda3\envs\py34\lib\site-packages\zmq\eventloop\", line 106, in __init__
    self.io_loop = io_loop or IOLoop.current()
File "D:\Users\admin\anaconda3\envs\py34\lib\site-packages\zmq\eventloop\", line 127, in current
    loop = ioloop.IOLoop.current(*args, **kwargs)
File "D:\Users\admin\anaconda3\envs\py34\lib\site-packages\tornado\", line 263, in current
    loop = asyncio.get_event_loop()
File "D:\Users\admin\anaconda3\envs\py34\lib\asyncio\", line 642, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'

Expected behavior:

Open and browser and show my app

Actual behavior:

Open the browser and throws a RuntimeError

Debug info

  • Streamlit version: 1.13.0
  • Python version: 3.9.12
  • Using Conda
  • Browser version: Chrome 106.0.5249.119

What is the file name and contents of the actual app you are trying to launch? The terminal snippet looks like it’s trying to prompt you how to run a streamlit app (streamlit run, but it’s filling it in with the file buried in the environment files.

Whatever streamlit code you wrote up, if you saved it in a file called, then you would want to

  1. Launch your environment terminal
  2. Change directory (cd) to where you have your file saved
  3. Use streamlit run to start it up

If that’s what you did, then a little more clarity on what you are trying to run would be helpful.

1 Like
PS F:\pythonProject> f:
PS F:\pythonProject> cd F:\pythonProject\venv
PS F:\pythonProject\venv> streamlit run

  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8501
  Network URL:

2022-10-27 09:45:42.988 Uncaught exception
Traceback (most recent call last):
  File "F:\Python-3.9.15\lib\site-packages\tornado\", line 276, in _read_message
  File "F:\Python-3.9.15\lib\site-packages\tornado\", line 268, in finish
  File "F:\Python-3.9.15\lib\site-packages\tornado\", line 2322, in finish
  File "F:\Python-3.9.15\lib\site-packages\tornado\", line 2344, in execute
    self.handler = self.handler_class(
  File "F:\Python-3.9.15\lib\site-packages\tornado\", line 224, in __init__
    super().__init__(application, request, **kwargs)
  File "F:\Python-3.9.15\lib\site-packages\tornado\", line 215, in __init__
  File "F:\Python-3.9.15\lib\", line 1083, in _no_init
    raise TypeError('Protocols cannot be instantiated')
TypeError: Protocols cannot be instantiated
2022-10-27 09:45:43.009 Uncaught exception
Traceback (most recent call last):

I tried what your suggestion but it didn’t work. I did the same thing on my mac and it worked well.

Do you mean it works on Mac but not on Windows? Or did you mean it didn’t work also. (Just to be sure I’m understanding you here.)

Can you provide the code of the app you are trying to launch? I am seeing your terminal execute the streamlit run command and report back that it launched the app. Did your default browser open? Is there an error message there? If not, can you navigate to localhost:8501 after running streamlit run to see what is displaying. Streamlit reports error messages within the app that can be more helpful than what is displaying in your terminal.