Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/python/impactx/dashboard/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
License: BSD-3-Clause-LBNL
"""

import asyncio

from . import server, state
from .app import application
from .Input.defaults import DashboardDefaults
Expand Down Expand Up @@ -42,6 +44,18 @@ class DashboardApp:

def start(self):
setup_dashboard()

# Ensure an event loop exists for Python 3.10+ (required on macOS)
# This prevents RuntimeError when server.start() tries to get_event_loop()
# In Python 3.10+, get_event_loop() raises RuntimeError if no loop exists
# We create and set one if needed
try:
asyncio.get_event_loop()
except RuntimeError:
# No event loop exists in this thread, create and set one
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

server.start()
return 0

Expand Down
8 changes: 8 additions & 0 deletions tests/python/dashboard/test_python_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def test_python_import(dashboard):
"""
dashboard.load_example("testdata/example.py", manual=True)

# Wait for the dashboard to finish loading the example file
# This ensures all UI elements are rendered before we check their values
dashboard.sb.wait_for_element_present("#Input_route", timeout=10)

BEAM_PARAMETERS = [
("tracking_mode", "Particle Tracking"),
("space_charge", "false"),
Expand Down Expand Up @@ -72,6 +76,10 @@ def test_python_import(dashboard):

# Check input values
for element_id, expected_value in DISTRIBUTION_VALUES + LATTICE_CONFIGURATION:
# Wait for element to be visible before getting its value
# This is important for CI environments where rendering may be slower
dashboard.sb.wait_for_element_visible(element_id, timeout=10)

actual_value = float(dashboard.sb.get_value(element_id))
assert actual_value == pytest.approx(expected_value, **APPROX_TOL), (
f"{element_id}: expected {expected_value}, got {actual_value}"
Expand Down
Loading