From b29e2b8cb5b7d2921ca28049ba2d97f2e27625b9 Mon Sep 17 00:00:00 2001 From: Stephane Rigaud Date: Wed, 20 Nov 2024 18:36:30 +0100 Subject: [PATCH] use try/except --- pyclesperanto/_core.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pyclesperanto/_core.py b/pyclesperanto/_core.py index 40f204d5..f5112099 100644 --- a/pyclesperanto/_core.py +++ b/pyclesperanto/_core.py @@ -148,12 +148,16 @@ def wait_for_kernel_to_finish(wait: bool = True, device: Device = None): def default_initialisation(): """Set default backend and device""" - backends = list_available_backends() - if backends: - _ = select_backend(backends[-1]) - else: + try: + backends = list_available_backends() + if backends: + _ = select_backend(backends[-1]) + else: + raise RuntimeError("No backend available.") + except Exception as e: warnings.warn( - "No GPU backend found.\n\n" + f"Error while initialising pyclesperanto: {e}\n\n" + "No GPU Backend found.\n\n" "pyclesperanto requires either CUDA or OpenCL libraries to be installed on your system to work.\n" "Please ensure you have the appropriate drivers installed and up-to-date.\n\n" "Alternatively, you may need to install the following additional package:\n"