changeset 572:9f5891cd4048

added host name and workdir to the db
author Olivier Breuleux <breuleuo@iro.umontreal.ca>
date Wed, 03 Dec 2008 23:23:03 -0500
parents 13bc6620ad95
children cf19655ec48b ef424abb7458
files pylearn/dbdict/newstuff.py
diffstat 1 files changed, 24 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/pylearn/dbdict/newstuff.py	Wed Dec 03 22:29:40 2008 -0500
+++ b/pylearn/dbdict/newstuff.py	Wed Dec 03 23:23:03 2008 -0500
@@ -2,8 +2,7 @@
 from __future__ import with_statement
 
 from collections import defaultdict
-import re, sys, inspect, os, signal, tempfile, shutil
-
+import re, sys, inspect, os, signal, tempfile, shutil, socket
 
 import sql
 
@@ -38,20 +37,10 @@
 ################################################################################
 
 def convert(obj):
-    return eval(obj)
-#     if not isinstance(obj, str):
-#         return obj
-#     def kw(x):
-#         x = x.lower()
-#         return dict(true = True,
-#                     false = False,
-#                     none = None)[x]
-#     for f in (kw, int, float):
-#         try:
-#             return f(obj)
-#         except:
-#             pass
-#     return obj
+    try:
+        return eval(obj, {}, {})
+    except NameError:
+        return obj
 
 def flatten(obj):
     d = {}
@@ -252,7 +241,7 @@
                            'The job is already running.')
         self.state.dbdict.status = self.RUNNING
 
-        v = self.INCOMPLETE
+        v = self.COMPLETE
         with self:
             try:
                 v = self.experiment(self, self.state)
@@ -402,6 +391,8 @@
 
 class DBRSyncChannel(RSyncChannel):
 
+    RESTART_PRIORITY = 2.0
+
     def __init__(self, username, password, hostname, dbname, tablename, path, remote_root):
         self.username, self.password, self.hostname, self.dbname, self.tablename \
             = username, password, hostname, dbname, tablename
@@ -418,11 +409,14 @@
             raise JobError(JobError.NOJOB,
                            'No job was found to run.')
 
-        state = expand(self.dbstate)
-        experiment = resolve(state.dbdict.experiment)
-
-        remote_path = os.path.join(remote_root, self.dbname, self.tablename, str(self.dbstate.id))
-        super(DBRSyncChannel, self).__init__(path, remote_path, experiment, state)
+        try:
+            state = expand(self.dbstate)
+            experiment = resolve(state.dbdict.experiment)
+            remote_path = os.path.join(remote_root, self.dbname, self.tablename, str(self.dbstate.id))
+            super(DBRSyncChannel, self).__init__(path, remote_path, experiment, state)
+        except:
+            self.dbstate['dbdict.status'] = self.START
+            raise
 
     def save(self):
         super(DBRSyncChannel, self).save()
@@ -432,11 +426,18 @@
         # Extract a single experiment from the table that is not already running.
         # set self.experiment and self.state
         super(DBRSyncChannel, self).setup()
+        self.state.dbdict.sql.host_name = socket.gethostname()
+        self.state.dbdict.sql.host_workdir = self.path
+        self.dbstate.update(flatten(self.state))
 
     def run(self):
         # We pass the force flag as True because the status flag is
         # already set to RUNNING by book_dct in __init__
-        return super(DBRSyncChannel, self).run(force = True)
+        v = super(DBRSyncChannel, self).run(force = True)
+        if v is self.INCOMPLETE and self.state.dbdict.sql.priority != self.RESTART_PRIORITY:
+            self.state.dbdict.sql.priority = self.RESTART_PRIORITY
+            self.save()
+        return v