Hi,

I'm pretty new to Django and am having a problem with a race conditions 
while modifying my session data. I'm using the standard session backend in 
Django 1.4.1,, backed by Mysql.

I have view A, which can take a long time to process, and view B, which is 
usually faster. I store multiple data fields, fieldA and fieldB, in the 
session dictionary. View A modifies fieldA, and view B modifies fieldB.

Sometimes, view A starts up with a copy of the session data as it exists at 
t1. Then, while it's processing, view B starts up. It completes quickly, 
modifying fieldB in the session data at time t2. Then view A finally 
completes, modifying its field in the session data at time t3. But what I 
wind up with is fieldA at time t3 and fieldB at time t1. In other words, 
when view A completes its write, it's storing the stale version of fieldB 
that it read when it started. What I want in that situation is t3's version 
of fieldA and t2's version of fieldB.

My questions: (1) is there a way to check if your copy of the session 
dictionary is stale? And if so, is there a way to do it atomically? (2) Is 
there a way to selectively write just part of the session data, instead of 
the whole thing? (3)  Or, is there a better solution besides either of 
these ideas?

The only thing I can think of using RAM memory to keep track of a 
last_write timestamp for each session -- but that's not a scalable 
solution. Is there a better way?

Thanks in advance,

Spork

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" 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/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to