]> gerrit.simantics Code Review - simantics/python.git/commitdiff
Report and log failure of Python DLL loading 99/3399/1 release/1.35.1 release/1.35.2 release/1.35.3
authorReino Ruusu <reino.ruusu@semantum.fi>
Wed, 23 Oct 2019 19:28:22 +0000 (22:28 +0300)
committerReino Ruusu <reino.ruusu@semantum.fi>
Wed, 23 Oct 2019 19:28:22 +0000 (22:28 +0300)
gitlab #2

Change-Id: I2e568ca49e0974cb4b7aedbdc14e00c594f991e8

org.simantics.pythonlink/META-INF/MANIFEST.MF
org.simantics.pythonlink/src/org/simantics/pythonlink/Activator.java
org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java

index 427f880d040b4c1ba3eb48433f26e2689cab3e89..36a734c5987595e11ad598f71b79085093e44642 100644 (file)
@@ -20,3 +20,4 @@ Require-Bundle: org.junit,
 Export-Package: org.simantics.pythonlink\r
 Bundle-Activator: org.simantics.pythonlink.Activator\r
 Bundle-ActivationPolicy: lazy\r
+Import-Package: org.slf4j\r
index 83633a4114c9282b0e86c65f06975681db66c6ae..26798d6f0b6fa53e33a0c4913bfd76195daa8be6 100644 (file)
@@ -2,11 +2,16 @@ package org.simantics.pythonlink;
 \r
 import org.osgi.framework.BundleActivator;\r
 import org.osgi.framework.BundleContext;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
 \r
 public class Activator implements BundleActivator {\r
 \r
+       private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);\r
        private static BundleContext context;\r
 \r
+       private static boolean loaded = false;\r
+       \r
        static BundleContext getContext() {\r
                return context;\r
        }\r
@@ -17,7 +22,16 @@ public class Activator implements BundleActivator {
         */\r
        public void start(BundleContext bundleContext) throws Exception {\r
                Activator.context = bundleContext;\r
-        System.loadLibrary("jnipython");\r
+               try {\r
+                       System.loadLibrary("jnipython");\r
+                       loaded = true;\r
+               } catch (Exception e) {\r
+                       LOGGER.error("Loading of jnipython.dll failed", e);\r
+               }\r
+       }\r
+       \r
+       public static boolean isPythonLoaded() {\r
+               return loaded;\r
        }\r
 \r
        /*\r
index cceace3c4d1b2bf9b372eeb4182d50eede2ba794..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;