]> gerrit.simantics Code Review - simantics/python.git/blobdiff - org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java
Report and log failure of Python DLL loading
[simantics/python.git] / org.simantics.pythonlink / src / org / simantics / pythonlink / PythonContext.java
index 62703f0795f0d80c6b915cf5c4022d7cfa3c71cd..77701ef5b352423e18d66ae90790dc296c178091 100644 (file)
@@ -57,6 +57,10 @@ public class PythonContext implements Closeable {
     };
     
     private static synchronized void ensurePythonInit() {
+       if (!Activator.isPythonLoaded()) {
+               throw new PythonException("Python interpreter has not been successfully loaded. Check availablility of python3.dll in path.");
+       }
+       
                if (!isPyInitialized) {
                        execute(() -> initializePython(pythonWriter));
                        isPyInitialized = true;
@@ -318,16 +322,28 @@ public class PythonContext implements Closeable {
        static void execute(Runnable job) {
         try {
             pythonExecutor.submit(job).get();
-        } catch (InterruptedException | ExecutionException e) {
+        } catch (InterruptedException e) {
             throw new RuntimeException(e);
+        } catch (ExecutionException e) {
+            Throwable cause = e.getCause();
+            if (cause instanceof RuntimeException)
+                throw (RuntimeException) cause;
+            else
+                throw new RuntimeException(cause);
         }
     }
     
     static <V> V execute(Callable<V> job) {
         try {
             return pythonExecutor.submit(job).get();
-        } catch (InterruptedException | ExecutionException e) {
+        } catch (InterruptedException e) {
             throw new RuntimeException(e);
+        } catch (ExecutionException e) {
+            Throwable cause = e.getCause();
+            if (cause instanceof RuntimeException)
+                throw (RuntimeException) cause;
+            else
+                throw new RuntimeException(cause);
         }
     }