During a single request, the "session" object is just a copy of the session 
data stored in the session file. Any updates to the session during a 
request are not written back out to the session file until after the 
request has completed. So, in the progress() function, you are not updating 
the session file itself every second, you are only updating that request's 
local copy of the session data. Repeated calls to getprogress() will 
therefore only see the original value from the session.

Anthony

On Tuesday, February 16, 2016 at 4:15:06 PM UTC-5, Alfonso Serra wrote:
>
> Im trying to make a progress bar by reading and writing a session variable:
>
> There are 2 controllers:
>
> Get session.progress
> def getprogress():
>     print "getprogress:", session.progress
>     return session.progress
>
> This one takes 5 seconds to perform and changes session.progress each one.
> def progress():
>     # when a form is submitted, change progress each second
>     if request.post_vars:
>         for i in range(5):
>             session.progress = i
>             print "main:", session.progress
>             sleep(1)
>         return "done"
>     else:
>         session.progress = -1
>     return locals()
>
> At the view, there are two ajax calls. One that triggers "getprogress" 
> each second, and another one that triggers "progress" when a random form is 
> submitted through ajax to avoid redirection.
>
> at the browser's console, getprogress only returns -1
>
> at the python console i get a log like this:
> getprogress: -1
> getprogress: -1
> main: 0
> getprogress: -1
> main: 1
> getprogress: -1
> main: 2
> getprogress: -1
> main: 3
> getprogress: -1
> main: 4
> getprogress: -1
>
> getprogress should be changing since im writing the session variable.
>
> If im changing a session variable in a controller why hasnt changed when i 
> ask for it on another one?
>
> Should i be using cron jobs or threads to make a progress bar? Whats the 
> best way?
>
> Thank you very much.
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.

Reply via email to