Adding exit code stats
[paralleljobs.git] / paralleljobs.py
index 535921c758b70c6bd09707e05a50ff31cdd9281d..5c309cd7e7118f677161ebbbd0e7519b81cb3727 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 """ A simple tool to run jobs from a database in parallel."""
 
 __author__ = "Stefan Huber"
@@ -34,14 +34,24 @@ def printStatusInfo(conn):
     c.execute("SELECT sum(workloadestm) FROM jobs;")
     wltotal, = c.fetchone()
 
-    c.close()
 
-    perdone = 100.0*float(nodone)/float(nototal)
-    perwl = 100.0*float(wldone)/float(wltotal)
+    perdone = 0
+    perwl = 0
+    if nototal > 0:
+        perdone = 100.0*float(nodone)/float(nototal)
+    if wltotal > 0:
+        perwl = 100.0*float(wldone)/float(wltotal)
 
     print("%d (%.1f%%) of %d jobs and %.1f%% of the workload done. %d jobs are running." % \
             (nodone, perdone, nototal, perwl, nostarted-nodone))
 
+    print("Exit code stats:")
+    c.execute("SELECT exitcode, count(exitcode) AS cnt FROM jobs GROUP BY exitcode ORDER BY exitcode ASC;")
+    for code, cnt in c.fetchall():
+        print("  %3s: %6s  (%5.1f%%)" % (code, cnt, 100.0*float(cnt)/nodone))
+
+    c.close()
+
 def createPropertiesTable(conn, propdef):
     conn.execute("BEGIN EXCLUSIVE")
 
@@ -246,7 +256,7 @@ if __name__ == "__main__":
         print("No database given.")
         sys.exit(os.EX_USAGE)
 
-    conn = sqlite3.connect(dbfn)
+    conn = sqlite3.connect(dbfn, timeout=60)
     createSchema(conn)
 
     if status: