can't reproduce right now, but usually for this kind of stuff I'd use a totally external process. Beware that "several minutes" standing requests may be killed by your webserver to free up resources (usually governed by the timeout* parameters).
If you'd like to have that running inside your webserver process, I'd adopt a slightly different pattern.... 1. page that display and process form 2. upon correct submission, call another function with the recalculateEvent via ajax 3. open a div somewhere to poll for status progress So you'd have: a) a thread that processes the form and then return ASAP rendering your "template" page b) a thread that does recalculateEvent, called one-time-only by the a) rendered page c) a thread that reports execution and returns ASAP, called several times by the a) rendered page, filling a component within the "template" page for b) and c) putting a session.forget() at the top should do no harm. On Tuesday, January 29, 2013 12:29:03 PM UTC+1, Andriy wrote: > > I have a time consuming server side calculation, which is triggered by > edit-form submitting and can run up to several minutes (its a sports event > data recalculation if rules are changed). During this time I want to > receive messages via ajax from server and post them in a div for a progress > visualization. So far I`v done this using DB table for recording log > messages: > > *db.py:* > #here I store messages > db.define_table('log', Field('message', 'string')) > > *controller #1:* > def editForm(): > ... > if form.process().accepted: > event=db(db.event.id==request.get_vars.id).select().first() > recalculateEvent(event) > > *myModel.py:* > #recalculation must be accessible from all controller files, so I put it > in a Model > import myModule > > recalculateEvent(event): > db.log.truncate() #clear log > session._unlock(response) #without this, this function does not > allow functions in other controllers to run > db.log.insert(message='Starting Calculation') > db.commit() #if I do not commit after every > insert, messages do not appear in DB table > myModule.calculateSomeMoreData() > for p in players: > db.log.insert(message='Calculating player '+p.name) > db.commit() > ...more calculations... > p.update_record() > > *controller#2:* > #ajax calls this function every .5 seconds for messages > def getProgress(): > m=' '.join([l.message for l in db(db.log).select()]) > return json.dumps(dict(m=m)) > > *View, javascript:* > $("#submit_button").click(function(e){ > $('#progress').show(); > GetProgres(); > $("#myForm").submit(); > }); > function GetProgres() { > $.ajax({ > type: "POST", > url: '{{=URL('controller#2', 'getProgress')}}', > dataType: "json", > success: function(data) { > $('#progress').html(data.m); > setTimeout(function() { GetProgres(); }, 500); > }, > error: function (xhr, ajaxOptions, thrownError){ > alert(xhr.status); > alert(xhr.statusText); > alert(thrownError); > } > }); > } > > I have 2 problems with this: > > 1. Every other time web2py throws this error after recalculateEvent(event) > function completes: > Traceback (most recent call last): > File "gluon/main.py", line 576, in wsgibase > File "gluon/globals.py", line 749, in _try_store_in_cookie_or_file > File "gluon/globals.py", line 768, in _try_store_in_file > IOError: [Errno 13] Permission denied > > If I remove db.log.insert+db.commit lines - no error. But how else can I > transfer live data between running real-time function in a model and > function in a controller? I tried storing messages in a session, but it > does not update until model function is finished. > > 2. Ajax call from view works only when hosting on my local machine and > only in Opera and IE. It does not call controller#2/getProgress function in > Chrome and Firefox on localhost. When hosting on outside server it does not > work on any browser... Only Firefox triggers ajax error, with > xhr.statusText='error'. > > I guess this is something to do with that I`m triggering form submission, > calculation function and at the same time polling sever. But I have no idea > what to do. > > May be if my approach is totally wrong somebody can suggest how to > implement this in other way. > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.