From d91d322193a871f07b0c3750dcc54a5f9783bcbc Mon Sep 17 00:00:00 2001
From: Martin Bauer <martin.bauer@fau.de>
Date: Thu, 11 Jul 2019 16:17:00 +0200
Subject: [PATCH] cpujit: try second time if module could not be loaded

---
 pystencils/cpu/cpujit.py | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/pystencils/cpu/cpujit.py b/pystencils/cpu/cpujit.py
index c2561c149..3809054ab 100644
--- a/pystencils/cpu/cpujit.py
+++ b/pystencils/cpu/cpujit.py
@@ -401,9 +401,19 @@ def create_module_boilerplate_code(module_name, names):
 
 def load_kernel_from_file(module_name, function_name, path):
     from importlib.util import spec_from_file_location, module_from_spec
-    spec = spec_from_file_location(name=module_name, location=path)
-    mod = module_from_spec(spec)
-    spec.loader.exec_module(mod)
+    try:
+        spec = spec_from_file_location(name=module_name, location=path)
+        mod = module_from_spec(spec)
+        spec.loader.exec_module(mod)
+    except ImportError:
+        import time
+        import warnings
+        warnings.warn("Could not load " + path + ", trying on more time...")
+        time.sleep(1)
+        spec = spec_from_file_location(name=module_name, location=path)
+        mod = module_from_spec(spec)
+        spec.loader.exec_module(mod)
+
     return getattr(mod, function_name)
 
 
-- 
GitLab