mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-14 05:14:19 +00:00
[BugFix] No event loop when exporting images (#6249)
* duplicated warning * if the event loop was closed - create a new one to process the image
This commit is contained in:
@@ -152,7 +152,6 @@ class Backend(PyWry):
|
||||
theme: Optional[str] = None,
|
||||
) -> dict:
|
||||
"""Get the json update for the backend."""
|
||||
|
||||
posthog: Dict[str, Any] = dict(collect_logs=self.charting_settings.log_collect)
|
||||
if (
|
||||
self.charting_settings.log_collect
|
||||
@@ -222,6 +221,11 @@ class Backend(PyWry):
|
||||
self.send_outgoing(outgoing)
|
||||
|
||||
if export_image and isinstance(export_image, Path):
|
||||
if self.loop.is_closed():
|
||||
# Create a new event loop
|
||||
self.loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(self.loop)
|
||||
|
||||
self.loop.run_until_complete(self.process_image(export_image))
|
||||
|
||||
async def process_image(self, export_image: Path):
|
||||
@@ -507,6 +511,7 @@ if not PLOTLYJS_PATH.exists() and not JUPYTER_NOTEBOOK:
|
||||
|
||||
|
||||
def create_backend(charting_settings: Optional["ChartingSettings"] = None):
|
||||
"""Create the backend."""
|
||||
# # pylint: disable=import-outside-toplevel
|
||||
from openbb_core.app.model.charts.charting_settings import ChartingSettings
|
||||
|
||||
@@ -517,6 +522,7 @@ def create_backend(charting_settings: Optional["ChartingSettings"] = None):
|
||||
|
||||
|
||||
def get_backend() -> Backend:
|
||||
"""Get the backend instance."""
|
||||
if BACKEND is None:
|
||||
raise ValueError("Backend not created")
|
||||
return BACKEND
|
||||
|
||||
@@ -923,11 +923,7 @@ class OpenBBFigure(go.Figure):
|
||||
# If the backend fails, we just show the figure normally
|
||||
# This is a very rare case, but it's better to have a fallback
|
||||
|
||||
if getattr(self._charting_settings, "debug_mode", False):
|
||||
warn(f"Failed to show figure with backend: {e}")
|
||||
warn(
|
||||
f"Failed to show figure with backend: {e}"
|
||||
) # remove this line when the above lines are figured out
|
||||
warn(f"Failed to show figure with backend. {e}")
|
||||
|
||||
# We check if any figures were initialized before the backend failed
|
||||
# If so, we show them with the default plotly backend
|
||||
|
||||
Reference in New Issue
Block a user