ThinkRAG icon indicating copy to clipboard operation
ThinkRAG copied to clipboard

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

Open Yanchi98 opened this issue 1 year ago • 0 comments

Version

python 3.9.0 Other packages: as specified in requirements.txt

Description

When executing the command “streamlit run app.py”, the application encounters a RuntimeError

RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'.
Traceback:
File "/opt/anaconda3/envs/py39/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling
    result = func()
File "/opt/anaconda3/envs/py39/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 590, in code_to_exec
    exec(code, module.__dict__)
File "/Users/yanchiliu/Documents/llm/github/ThinkRAG/app.py", line 10, in <module>
    from frontend.state import init_keys
File "/Users/yanchiliu/Documents/llm/github/ThinkRAG/frontend/state.py", line 9, in <module>
    from server.index import IndexManager
File "/Users/yanchiliu/Documents/llm/github/ThinkRAG/server/index.py", line 10, in <module>
    from server.ingestion import AdvancedIngestionPipeline
File "/Users/yanchiliu/Documents/llm/github/ThinkRAG/server/ingestion.py", line 9, in <module>
    from server.stores.ingestion_cache import INGESTION_CACHE
File "/Users/yanchiliu/Documents/llm/github/ThinkRAG/server/stores/ingestion_cache.py", line 6, in <module>
    cache=RedisCache(redis_uri=REDIS_URI),
File "/opt/anaconda3/envs/py39/lib/python3.9/site-packages/llama_index/storage/kvstore/redis/base.py", line 65, in __init__
    self._async_redis_client = AsyncRedis.from_url(redis_uri, **kwargs)
File "/opt/anaconda3/envs/py39/lib/python3.9/site-packages/redis/asyncio/client.py", line 164, in from_url
    client = cls(
File "/opt/anaconda3/envs/py39/lib/python3.9/site-packages/redis/asyncio/client.py", line 342, in __init__
    self._single_conn_lock = asyncio.Lock()
File "/opt/anaconda3/envs/py39/lib/python3.9/asyncio/locks.py", line 81, in __init__
    self._loop = events.get_event_loop()
File "/opt/anaconda3/envs/py39/lib/python3.9/asyncio/events.py", line 642, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'

The error originates from the “ingestion_cache.py”

redis_cache=IngestionCache(
    cache=RedisCache(redis_uri=REDIS_URI),
    collection="redis_pipeline_cache",
)

INGESTION_CACHE = redis_cache if not DEV_MODE else None

Temporary Solution

Setting INGESTION_CACHE to None when DEV_MODE is enabled bypasses the initialization of the Redis cache, allowing the application to run successfully.

Yanchi98 avatar Sep 09 '24 15:09 Yanchi98