WhoooO !

Thanks for the answer Niphold, but a bit slower please ;-)

If I understand your answer, my problem with asking web2py to stream a 
generator is not working anymore since I changed from the provided web 
server to Apache.
BTW, I tried by removing the database accesses, and it does not behave as 
expected on Apache server, while in embedded web2py server it just works. 
(I posted the code below).

So, basically I have 2 problems :
1. WSGI that breaks the streaming of generators.
2. Access to db in SQLite that is dying (not sure why...), and producing 
the Closed Database error.

I'm looking for a very simple method, mainly used for an intranet 
application, with probably no concurency. (Less than 10 uses per day.)
Using a generator in web2py was to my eyes a nice way to avoid any AJAX.

So, what should I do??

For my problem 1, should I go back to Web2Py embedded server, and continue 
with a generator, or should I turn to an other solution. Is there any 
simple solution with a simple xmlhttprequest & consise example? Should I 
have a blocking controller that is being called by an XMLHTTPRequest with 
the comet/long polling technique? Is there samples? Ho to I manage my 
background process? Worker? If worker, how can I communicate with my 
controller? Message Queuing system, pipe, db?
I need a simple solution or have to abandon the idea of a realtime feedback 
in my web page, but it's really too bad.

For my problem 2, SQLite is really perfect for the use I have, it would be 
too bad to have to use a more complex DB, and manage the import/export 
scripts so the data are in the w2p package... with SQLite & a generator, I 
suppose the only way is to reconnect to the DB at every iteration ? Will I 
have the same problem if I implement a Class that will instanciate and keep 
the db open (and add a next() function) ? 

I know it's a lot of question. Thanks for any advise that could help me 
here.

Here is my processing function simplified that works on Web2Py web server, 
but not on Apache with WSGI. :
def processing():
    def createGenerator() :
        for i in xrange(20):
            time.sleep(0.2)
            outline = '<p>My Name is : \n'
            yield outline
            time.sleep(0.2)
            yield outline
            time.sleep(0.2)
    mygen = createGenerator()
    return mygen



Le vendredi 4 mai 2012 11:51:30 UTC+2, François Delpierre a écrit :
>
> 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,
>
>
>

Reply via email to