chiark / gitweb /
rhodes: Don't try to kill ourselves when zapping redundant workers.
[rhodes] / rhodes
diff --git a/rhodes b/rhodes
index 4d30aeaf75294d814dcbe35df710ff9acf83fbbf..b9d97fa602241fccedce9748f371d7f1dd5a5619 100755 (executable)
--- a/rhodes
+++ b/rhodes
@@ -193,6 +193,17 @@ def check(dir):
   if not G.idp(G.pow(x, m)):
     bad('x not in group: %s^%d /= 1' % (G.str(x), m))
 
+  ## Clear away old workers that aren't doing anything useful any more.
+  ## For each worker pid, check that its lockfile is still locked; if
+  ## not, it's finished and can be disposed of.
+  c.execute("""SELECT pid FROM workers""")
+  for pid, in c:
+    maybe_cleanup_worker(dir, db, pid)
+  for f in OS.listdir(dir):
+    if f.startswith('lk.'):
+      pid = int(f[3:])
+      maybe_cleanup_worker(dir, db, pid)
+
   c.execute("""SELECT p.p, p.e, p.k, p.n, p.dpbits, COUNT(d.z)
                FROM progress AS p LEFT OUTER JOIN points AS d
                ON p.p = d.p AND p.k = d.k
@@ -275,7 +286,7 @@ def maybe_cleanup_worker(dir, db, pid):
 
 def maybe_kill_worker(dir, pid):
   f = OS.path.join(dir, 'lk.%d' % pid)
-  try: fd = OS.open(f, OS.O_RDONLY)
+  try: fd = OS.open(f, OS.O_RDWR)
   except OSError, err:
     if err.errno != E.ENOENT: raise ExpectedError, 'open lockfile: %s' % err
     return
@@ -309,17 +320,6 @@ def step(dir, cmd, *args):
       G, g, x, m, n = get_top(db)
       if n is not None: raise ExpectedError, 'job done'
 
-      ## Clear away old workers that aren't doing anything useful any more.
-      ## For each worker pid, check that its lockfile is still locked; if
-      ## not, it's finished and can be disposed of.
-      c.execute("""SELECT pid FROM workers""")
-      for pid, in c:
-        maybe_cleanup_worker(dir, db, pid)
-      for f in OS.listdir(dir):
-        if f.startswith('lk.'):
-          pid = int(f[3:])
-          maybe_cleanup_worker(dir, db, pid)
-
       ## Find something to do.  Either a job that's small enough for us to
       ## take on alone, and that nobody else has picked up yet, or one that
       ## everyone's pitching in on.
@@ -466,7 +466,8 @@ def step(dir, cmd, *args):
       ## we lose a bunch of work. :-(
       c.execute("""SELECT pid FROM workers WHERE p = ? AND k = ?""",
                 (str(p), k))
-      for pid, in c: maybe_kill_worker(dir, pid)
+      for pid, in c:
+        if pid != mypid: maybe_kill_worker(dir, pid)
       c.execute("""DELETE FROM workers WHERE p = ? AND k = ?""",
                 (str(p), k - 1))
       c.execute("""DELETE FROM points WHERE p = ? AND k = ?""",
@@ -490,7 +491,8 @@ def step(dir, cmd, *args):
           p, n = C.MP(pstr), C.MP(nstr)
           qq.append(p**e)
           nn.append(n)
-        n = C.MPCRT(qq).solve(nn)
+        if len(qq) == 1: n = nn[0]
+        else: n = C.MPCRT(qq).solve(nn)
 
         ## One last check that this is the right answer.
         xx = G.pow(g, n)