hello! trying to run a baasic prefect flow inside ...
# ask-community
c
hello! trying to run a baasic prefect flow inside streamlit and am getting this error upon prefect import:
RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'.
any ideas?
full error:
Copy code
RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'.
Traceback:
File "/usr/local/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
    exec(code, module.__dict__)
File "/code/streamlit_dashboard.py", line 16, in <module>
    from utils import *
File "/code/utils.py", line 2, in <module>
    from prefect import flow, task
File "/usr/local/lib/python3.9/site-packages/prefect/__init__.py", line 45, in <module>
    from prefect.engine import pause_flow_run, resume_flow_run
File "/usr/local/lib/python3.9/site-packages/prefect/engine.py", line 128, in <module>
    from prefect.deployments import load_flow_from_flow_run
File "/usr/local/lib/python3.9/site-packages/prefect/deployments/__init__.py", line 1, in <module>
    import prefect.deployments.base
File "/usr/local/lib/python3.9/site-packages/prefect/deployments/base.py", line 465, in <module>
    OPEN_FILE_SEMAPHORE = asyncio.Semaphore(math.floor(get_open_file_limit() * 0.5))
File "/usr/local/lib/python3.9/asyncio/locks.py", line 375, in __init__
    self._loop = events.get_event_loop()
File "/usr/local/lib/python3.9/asyncio/events.py", line 642, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
n
can you share your code?
c
Copy code
from prefect import flow, task
import streamlit as st

@task
def say_hello(name):
    st.write(f"hello {name}")

@task
def say_goodbye(name):
    st.write(f"goodbye {name}")

@flow(name="test flow")
def greetings(names=["arthur", "trillian", "ford", "marvin"]):
    for name in names:
        say_hello(name)
        say_goodbye(name)

if __name__ == "__main__":
    greetings(["arthur", "trillian", "ford", "marvin"])
n
what happens if you do something like
Copy code
import asyncio
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
c
same thing
its happening on import of prefect
if i put it above the import i get :
n
hmm i am on 3.11 but your example is working for me
c
3.11? Latest streamlit and prefect?
Are you in docker?
I’m using 3.9-buster-slim I’ll try again when I get home with a full 3.11 container
n
Copy code
15:03:44.544 | INFO    | Task run 'say_goodbye-3' - Finished in state Completed()
15:03:44.683 | INFO    | Flow run 'rigorous-tapir' - Finished in state Completed('All states completed.')
^C  Stopping...

❯ pip list | rg -e prefect -e streamlit
prefect                   2.11.0
streamlit                 1.25.0

❯ python --version
Python 3.11.4

❯ uname -v
Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:19 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T8103
not docker, local, apple silicon
c
Ok
c
strange.. working now without changing anything