If I'm not mistaken as long as you're not going with green threads with
uwsgi (and then some, nothing is too simple with green threads) you need to
remember that returning a generator in a wsgi app basically means that the
webserver will pile up the complete response before actually starting to
stream it to the browser.
"Closed database" is also a specific error to the sqlite engine, the
connection is dropped after a while and there's no apparent way to fix it
....
The standard method to accomplish you goal is AJAX
Il giorno venerdì 4 maggio 2012 11:51:30 UTC+2, François Delpierre ha
scritto:
>
> 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,
>
>
>