One way to get the behaviour I want is to add to the top if index's GET:
if "uid" not in session.keys() :
session["uid"] = uuid.uuid4().hex
states[session["uid"]] = {}
then use states[session["uid"]]["state1"]
and states[session["uid"]]["state2"] instead of session["state1"] and
session["state2"]
I suppose this means the state is always held in memory, and it won't be
cleared out when the session expires.
Any better ideas?
On Friday, July 19, 2013 7:12:15 PM UTC+1, Matthew Henderson wrote:
>
> Hi,
>
> In my application I would like AJAX invoked GETs and POSTs to edit the
> state of the application by editing attributes in the session. I'm having
> trouble though when the requests overlap, meaning not all changes to the
> state are saved.
>
> Below is a minimal example to reproduce the problem. First visit /, then
> /status to see that only one of the session attributes is updated, not
> both. /status shows for me "state1 = 1 state2 = 0"
>
> Thanks in advance for any help,
>
> Matt
>
> import web, time
>
> urls = (
> '/', 'index',
> '/1', 'one',
> '/2', 'two',
> '/status', 'status',
> )
> web.config.debug = False
>
> app = web.application(urls, globals())
> session = web.session.Session(app, web.session.DiskStore('sessions'))
>
>
>
> class one(object):
> def GET(self):
> session.state1 = 1
> time.sleep(1)
> return "done"
>
> class two(object):
> def GET(self):
> session.state2 = 1
> return "done"
>
>
> class index(object):
> def GET(self):
> session["state1"] = 0
> session["state2"] = 0
> return """
> <iframe src="/1"></iframe><iframe src="/2"></iframe><a
> href="/status">status</a>
> """
>
> class status(object):
> def GET(self):
> out = ""
> if "state1" in session.keys() :
> out += "state1 = " + str(session["state1"])
> else :
> out += "state1 not set"
> if "state2" in session.keys() :
> out += " state2 = " + str(session["state2"])
> else :
> out += "state2 not set"
> return out
>
>
>
>
> if __name__ == '__main__':
> app.run()
>
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/groups/opt_out.