From 4a7da60f72bb5149dca9d23924ee16dca7421d46 Mon Sep 17 00:00:00 2001 From: Parthib Roy <159463257+proy30@users.noreply.github.com> Date: Wed, 2 Oct 2024 09:52:50 -0700 Subject: [PATCH] Print simulation content after simulation runs (#718) Improvement from current, however it would be ideal that the contents stream out on the terminal view as the simulation runs, not just at once when the simulation is completed. Using wurlitzer library for this --- src/python/impactx/dashboard/Analyze/plotsMain.py | 6 +++--- src/python/impactx/dashboard/requirements.txt | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/python/impactx/dashboard/Analyze/plotsMain.py b/src/python/impactx/dashboard/Analyze/plotsMain.py index 4d71ffb86..1202801f5 100644 --- a/src/python/impactx/dashboard/Analyze/plotsMain.py +++ b/src/python/impactx/dashboard/Analyze/plotsMain.py @@ -7,12 +7,12 @@ """ import asyncio -import contextlib import glob import io import os from trame.widgets import matplotlib, plotly, vuetify +from wurlitzer import pipes from ..trame_setup import setup_server from .analyzeFunctions import AnalyzeFunctions @@ -140,11 +140,11 @@ def update_plot(): def run_simulation_impactX(): buf = io.StringIO() - with contextlib.redirect_stdout(buf), contextlib.redirect_stderr(buf): + with pipes(stdout=buf, stderr=buf): state.simulation_data = run_simulation() buf.seek(0) - lines = [line.strip() for line in buf] + lines = [line.strip() for line in buf.getvalue().splitlines()] # Use $nextTick to ensure the terminal is fully rendered before printing async def print_lines(): diff --git a/src/python/impactx/dashboard/requirements.txt b/src/python/impactx/dashboard/requirements.txt index 7eaac07dc..0726649c2 100644 --- a/src/python/impactx/dashboard/requirements.txt +++ b/src/python/impactx/dashboard/requirements.txt @@ -6,3 +6,4 @@ trame-plotly>=3.0.2 trame-router>=2.2.0 trame-vuetify>=2.6.2 trame-xterm>=0.2.1 +wurlitzer>=3.1.1