Hi, Here is my problem. It looks like the databases closes while in my Generator. I also tried to pass the DB with the send() function as described in an other post.
In a web page, I have an iframe that calls a function that returns a generator to get some kind of "asynchronous" update in the web page. Here is a simpler example that illustrates the problem : View : {{extend 'layout.html'}} {{=form1}} <iframe src="../processing.html" width="90%" height="300"></iframe> Controller : def processing(): def createGenerator() : db = None while db is None: db = (yield "Thanks for initalizing the DB") assert db.tables[0] == 'auth_user' print "The db is available initialized" def tst(): return ('<div><span style="width:500px;width:300px;">Event ' + str(i*i) + ' : </span>') def tst2(): return ('<span style="color:red;width:200px;border-style:solid;border-width:1px;">ERROR</span></div>') for i in xrange(20): time.sleep(0.2) outline = '<div><span style="width:500px;width:300px;">My Name is : </span>' yield outline time.sleep(0.2) outline = ''' <span style=" color:red; width:200px; border-style:solid; border-width:1px;" >%s</span></div> ''' % db(db.auth_user).select().first()['first_name'] yield outline time.sleep(0.2) mygen = createGenerator() # I must run at least once the generator before using the send() function. print mygen.next() mygen.send(db) return mygen In the log, we see that first the database is available, then it's closed : [Fri May 04 11:44:08 2012] [error] Thanks for initalizing the DB [Fri May 04 11:44:08 2012] [error] The db is available initialized [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] mod_wsgi (pid=11492): Exception occurred processing WSGI script '/home/www-data/web2py/wsgihandler.py'. [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] Traceback (most recent call last): [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] File "/home/www-data/web2py/applications/init/controllers/default.py", line 232, in createGenerator [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] ''' % db(db.auth_user).select().first()['first_name'] [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] File "/home/www-data/web2py/gluon/dal.py", line 7578, in select [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] return adapter.select(self.query,fields,attributes) [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] File "/home/www-data/web2py/gluon/dal.py", line 1315, in select [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] rows = response(sql) [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] File "/home/www-data/web2py/gluon/dal.py", line 1305, in response [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] self.execute(sql) [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] File "/home/www-data/web2py/gluon/dal.py", line 1392, in execute [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] return self.log_execute(*a, **b) [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] File "/home/www-data/web2py/gluon/dal.py", line 1386, in log_execute [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] ret = self.cursor.execute(*a, **b) [Fri May 04 11:44:08 2012] [error] [client 10.242.0.10] ProgrammingError: Cannot operate on a closed database. I'm searching for some hours already on how to fix this issue. Or maybe is there a better solution to update the page in realtime / asynchronously ? Regards,