X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.pythonlink%2Fsrc%2Forg%2Fsimantics%2Fpythonlink%2FPythonContext.java;h=77701ef5b352423e18d66ae90790dc296c178091;hb=ef0dd0f438500b3ebea840a0d25fbe3103d1bd89;hp=62703f0795f0d80c6b915cf5c4022d7cfa3c71cd;hpb=8885425046e0f89893c0e1ee0fe5c27948dcd2be;p=simantics%2Fpython.git diff --git a/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java b/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java index 62703f0..77701ef 100644 --- a/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java +++ b/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java @@ -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 execute(Callable 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); } }