summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrique Joaquim <h.joaquim@campus.fct.unl.pt>2024-03-22 14:22:29 +0000
committerGitHub <noreply@github.com>2024-03-22 14:22:29 +0000
commit80d3ac613101886e210ee1d6f9d5506cf3a6ae07 (patch)
tree2cbe8287df6ee6e744b0b0c9d1b416de986418f2
parent78695fa6de3ee46182f5531f620d6607fd0cc1d9 (diff)
[BugFix] No event loop when exporting images (#6249)
* duplicated warning * if the event loop was closed - create a new one to process the image
-rw-r--r--openbb_platform/obbject_extensions/charting/openbb_charting/core/backend.py8
-rw-r--r--openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py6
2 files changed, 8 insertions, 6 deletions
diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/backend.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/backend.py
index ce8b706f5cc..457df7d5981 100644
--- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/backend.py
+++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/backend.py
@@ -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
diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py
index 27963e1cd5b..32e5876817f 100644
--- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py
+++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py
@@ -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