rhodes: Clear out debris from stale workers in `check'.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 28 May 2017 18:03:08 +0000 (19:03 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 19 Jun 2017 09:27:48 +0000 (10:27 +0100)
Doing this in every `step' leads to contention over the database, which
currently isn't handled well.

rhodes

diff --git a/rhodes b/rhodes
index 4d30aea..092e97a 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
@@ -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.