marvin
marvin copied to clipboard
Get marvin to import correctly when running other python processes on multiple threads
When import marvin into a streamlit app process, it kept conflicting with the main thread running the streamlit app. I worked around it by setting thread conditions within marvin to workaround this. Would love this to be a default.
# __init__.py
from importlib.metadata import version as _get_version
# load nest_asyncio
import nest_asyncio as _nest_asyncio
import asyncio as _asyncio
import threading
import asyncio as _asyncio
import threading
if threading.current_thread() == threading.main_thread():
_nest_asyncio.apply()
else:
_asyncio.set_event_loop(_asyncio.new_event_loop())
_nest_asyncio.apply()