Source code for cosedaUI.mainwindow_sections.cluster
import webbrowser
from PyQt6.QtWidgets import QApplication, QInputDialog, QMessageBox
from coseda.dask_client_manager import DaskClientManager
[docs]
class ClusterMixin:
[docs]
def on_set_cluster_address(self):
"""
Prompt for and set the Dask scheduler address override.
"""
addr, ok = QInputDialog.getText(
self,
"Dask Scheduler Address",
"Enter scheduler address (host:port):"
)
if ok and addr:
DaskClientManager.set_scheduler_address(addr)
QMessageBox.information(
self,
"Scheduler Override",
f"Override set to {addr}"
)
def _on_cluster_started(self):
# Restore cursor and menu, notify user
QApplication.restoreOverrideCursor()
self.dask_menu.setEnabled(True)
QMessageBox.information(self, "Dask", "New Dask cluster started.")
def _on_cluster_start_failed(self, errmsg: str):
# Restore cursor and menu, report error
QApplication.restoreOverrideCursor()
self.dask_menu.setEnabled(True)
QMessageBox.critical(self, "Dask Error", f"Failed to start new cluster:\n{errmsg}")
[docs]
def on_kill_current_cluster(self):
"""
Kill the current Dask cluster and inform the user.
"""
try:
DaskClientManager.kill_current_cluster()
QMessageBox.information(self, "Dask", "Current Dask cluster shutdown.")
except Exception as e:
QMessageBox.critical(self, "Dask Error", f"Failed to kill current cluster:\n{e}")
[docs]
def on_kill_all_clusters(self):
"""
Kill all Dask clusters on this machine and inform the user.
"""
try:
DaskClientManager.kill_all_dask_clusters()
QMessageBox.information(self, "Dask", "All Dask clusters have been killed.")
except Exception as e:
QMessageBox.critical(self, "Dask Error", f"Failed to kill all clusters:\n{e}")
[docs]
def on_open_dashboard(self):
"""
Opens the Dask dashboard URL for the current cluster in the default browser.
"""
try:
client = DaskClientManager.get_client()
except Exception as e:
QMessageBox.warning(self, "Dask Dashboard", "Failed to retrieve Dask client.")
return
if client is None or not hasattr(client, 'dashboard_link') or not client.dashboard_link:
QMessageBox.warning(self, "Dask Dashboard", "No active Dask cluster or dashboard URL unavailable.")
return
webbrowser.open(client.dashboard_link)