changeset 623:ae954c27fd11

looping works, eagerload of booked jobs works by str() HACK
author James Bergstra <bergstrj@iro.umontreal.ca>
date Sun, 18 Jan 2009 22:00:16 -0500
parents d2d582bcf7dc
children 25d9f91f1afa
files pylearn/dbdict/api0.py pylearn/dbdict/sql.py
diffstat 2 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pylearn/dbdict/api0.py	Sun Jan 18 21:39:28 2009 -0500
+++ b/pylearn/dbdict/api0.py	Sun Jan 18 22:00:16 2009 -0500
@@ -406,7 +406,10 @@
         h_self._Query = _Query
 
     def __iter__(h_self):
-        return h_self.query.__iter__()
+        s = h_self.session()
+        rval = list(h_self.query(s).__iter__())
+        s.close()
+        return rval.__iter__()
 
     def insert_kwargs(h_self, session=None, **dct):
         """
--- a/pylearn/dbdict/sql.py	Sun Jan 18 21:39:28 2009 -0500
+++ b/pylearn/dbdict/sql.py	Sun Jan 18 22:00:16 2009 -0500
@@ -80,12 +80,12 @@
     while (dct is None) and keep_trying:
         #build a query
         q = s.query(db._Dict)
-        #q = q.options(eagerload('_attrs')) #hard-coded in api0
 
         #N.B.
         # use dedicated column to retrieve jobs, not the dictionary keyval pair
         # This should be much faster.
         q = q.filter(db._Dict.status==START)
+        q = q.options(eagerload('_attrs')) #hard-coded in api0
 
         #try to reserve a dct
         try:
@@ -122,6 +122,8 @@
             wait = numpy.random.rand(1)*retry_max_sleep
             if verbose: print 'another process stole our dct. Waiting %f secs' % wait
             time.sleep(wait)
+    if dct:
+        str(dct) # for loading of attrs in UGLY WAY!!!
     s.close()
     return dct