chiark / gitweb /
curveopt: use a fresh findcurve process for each curve
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Apr 2018 13:00:25 +0000 (14:00 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Apr 2018 13:00:25 +0000 (14:00 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
curveopt.py

index fe19d5818521d88715d3d72983b873deea0096f1..87438895f199d5a34d028f03a1294fe0bae51afe 100644 (file)
@@ -17,8 +17,6 @@ from math import atan2, atan, sqrt
 
 import symbolic
 
-findcurve_subprocs = { }
-
 class OptimisedCurve():
   def __init__(oc, cp, nt):
     db = DiscreteBezier(cp, nt, bezier_constructor=BezierSegment)
@@ -43,22 +41,18 @@ class OptimisedCurve():
 
     findcurve_epsilon = 0.01
 
-    try:
-      subproc = findcurve_subprocs[nt]
-    except KeyError:
-      cl = ['./findcurve', '%d' % (nt+1), '%.18g' % findcurve_epsilon]
-      dbg('STARTING FINDCURVE %s' % cl)
-      subproc = subprocess.Popen(
-        cl,
-        bufsize=1,
-        stdin=subprocess.PIPE,
-        stdout=subprocess.PIPE,
-        stderr=None,
-        close_fds=False,
-        # restore_signals=True, // want python2 compat, nnng
-        universal_newlines=True,
-      )
-      findcurve_subprocs[nt] = subproc
+    cl = ['./findcurve', '%d' % (nt+1), '%.18g' % findcurve_epsilon]
+    dbg('STARTING FINDCURVE %s' % cl)
+    subproc = subprocess.Popen(
+      cl,
+      bufsize=1,
+      stdin=subprocess.PIPE,
+      stdout=subprocess.PIPE,
+      stderr=None,
+      close_fds=False,
+      # restore_signals=True, // want python2 compat, nnng
+      universal_newlines=True,
+    )
 
     dbg('RUNNING FINDCURVE')
 
@@ -90,6 +84,10 @@ class OptimisedCurve():
 
       findcurve_result = l
 
+    subproc.stdin.close()
+    subproc.wait()
+    assert(subproc.returncode == 0)
+
     oc.nt = nt
     oc._result = np.reshape(findcurve_result, (-1,3), 'C')
     dbg(repr(oc._result))