I don't think this has anything to do with cache.ram. If you're using the 
Pythonanywhere free tier, you only get 1 uWSGI worker, so your app can only 
handle one request at a time. You should observe the same issue if you make 
*any* concurrent requests, whether you're reading/writing to cache.ram or 
not.

Note, switching to a paid plan with multiple workers may not help either -- 
depending on how uWSGI is set up, there may be multiple processes, each 
with its own independent cache.ram (so different requests may hit different 
caches).

Anthony

On Monday, May 2, 2016 at 12:16:27 PM UTC-4, Alfonso Serra wrote:
>
> Im trying to use cache.ram for a progress bar and i have this problem.
>
> I have 2 controllers, 
> progress: that changes cache.ram each second 
> getprog: that retrieves the cache.ram value whenever i like.
>
> import json as Json
>
> #convert a variable into a json response
> def json(var):
>     response.headers['Content-Type'] = "application/json; charset=utf-8"
>     return Json.dumps(var, ensure_ascii=False)
>
> #get progress status
> def getprog():
>     msg = cache.ram('message', lambda: None, None)
>     return json({"msg": msg})
>
> #start a process that updates the progress
> def progress():
>     from time import sleep
>     # when a form is submitted, change progress each second
>     if request.ajax:
>         for i in range(10):
>             cache.ram('message', lambda: i, time_expire=0)
>             print "main:", i
>             sleep(1)
>         return "done"
>     else:
>         cache.ram('message', lambda: -1, time_expire=0)
>     return locals()
>
> When progress is triggered it begins to change cache.ram("message") each 
> second
>
> If i visit getprog when progress is working, on localhost works well, i 
> get the current value, but on pythonanywhere, getprog returns a response 
> when progress is finished, not while at it.
>
> Is there any parameter or way to tell cache.ram to return the current 
> value without waiting for other controllers to finish?
>
> Thanks.
>
> PD: i have tried without time.sleep, but i get the same result, cant ask 
> for the progress until the main controller (the one that updates cache.ram 
> finishes)
>

-- 
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