chiark / gitweb /
curveopt: limit no. of concurrent findcurves
[moebius3.git] / curveopt.py
index 33670210ca5554851c5ac4e4144a4fd015bf0d2c..5b8f2de155ded9edf4639c66290e8493f856f3bd 100644 (file)
@@ -12,6 +12,7 @@ import math
 from moedebug import *
 from moenp import *
 from moebez import *
+from schequeue import ScheduledTask
 
 from math import atan2, atan, sqrt
 
@@ -21,11 +22,12 @@ class OptimisedCurve():
   counter = 0
 
   def _dbg(oc, s):
-    dbg('OC#%04d %s' % (oc._counter, s))
+    dbg('%s %s' % (oc._desc, s))
 
   def __init__(oc, cp, nt):
-    oc._counter = OptimisedCurve.counter
+    oc._desc = 'OC#%04d' % OptimisedCurve.counter
     OptimisedCurve.counter += 1
+
     oc._dbg('cp= ' + ' '.join(map(vec2dbg, cp)))
 
     db = DiscreteBezier(cp, nt, bezier_constructor=BezierSegment)
@@ -50,6 +52,9 @@ class OptimisedCurve():
 
     findcurve_epsilon = 0.01
 
+    oc.sched = ScheduledTask(oc._await_subproc, oc._desc)
+    oc.sched.pre_spawn()
+
     cl = ['./findcurve', '%d' % (nt+1), '%.18g' % findcurve_epsilon]
     oc._dbg('STARTING FINDCURVE %s' % cl)
     subproc = subprocess.Popen(
@@ -76,6 +81,7 @@ class OptimisedCurve():
     oc.subproc = subproc
     oc.nt = nt
 
+    oc.sched.post_spawn()
     #oc._await_subproc()
 
   def _await_subproc(oc):
@@ -110,6 +116,8 @@ class OptimisedCurve():
     assert(subproc.returncode == 0)
     oc.subproc = None
 
+    oc.sched.post_reap()
+
     oc._result = np.reshape(findcurve_result, (-1,3), 'C')
     oc._dbg(repr(oc._result))