Browse Source

Fix wrapper for init to keep trying for some time (until Mv has loaded
completely)

Yentl Van Tendeloo 4 years ago
parent
commit
5c4db8b7fb
2 changed files with 17 additions and 8 deletions
  1. 4 2
      integration/utils.py
  2. 13 6
      wrappers/modelverse.py

+ 4 - 2
integration/utils.py

@@ -106,8 +106,10 @@ def compile_file(address, mod_filename, filename, mode, proc):
             pass
 
 def start_mvc():
-    address = "http://127.0.0.1:%s" % getFreePort()
-    proc = execute("run_MvC_server", [address], wait=False)
+    port = getFreePort()
+    address = "http://127.0.0.1:%s" % port
+    proc = execute("run_local_modelverse", [str(port)], wait=False)
+    return proc, address
     # TODO Return only when everything is fine! (i.e., parse the output of proc and wait until it contains "MvC is ready"
     while 1:
         l = proc.stdout.readline()

+ 13 - 6
wrappers/modelverse.py

@@ -4,6 +4,7 @@ import json
 import random
 from urllib2 import URLError
 import sys
+import time
 
 COMPILER_PATH = "interface/HUTN"
 
@@ -156,7 +157,7 @@ def _handle_output(requested=None, split=None):
         raise InterfaceMismatch(value)
     
 # Main MvC operations
-def init(address_param="http://127.0.0.1:8001"):
+def init(address_param="http://127.0.0.1:8001", timeout=10.0):
     """Starts up the connection to the Modelverse."""
     # return None
     # raises ConnectionError
@@ -167,11 +168,17 @@ def init(address_param="http://127.0.0.1:8001"):
         raise InvalidMode()
     global address
     address = address_param
-    try:
-        _input_raw('"%s"' % taskname, "task_manager")
-        mode = MODE_UNAUTHORIZED
-    except URLError as e:
-        raise ConnectionError(e.reason)
+    start_time = time.time()
+    while 1:
+        try:
+            _input_raw('"%s"' % taskname, "task_manager")
+            mode = MODE_UNAUTHORIZED
+            break
+        except URLError as e:
+            if time.time() - start_time > timeout:
+                raise ConnectionError(e.reason)
+            else:
+                time.sleep(0.1)
 
 def login(username, password):
     """Log in a user, if user doesn't exist, it is created."""