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
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
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.
## 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 = ?""",
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)