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)