# HG changeset patch # User Olivier Breuleux # Date 1228364583 18000 # Node ID 9f5891cd4048feff9d45472f5d2b8242d6d66fc9 # Parent 13bc6620ad9577878462d8a07760463d0b6ceba0 added host name and workdir to the db diff -r 13bc6620ad95 -r 9f5891cd4048 pylearn/dbdict/newstuff.py --- 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