Updated to make thread-safe in Django. 

This works with Django, but I did not test it with the webapp framework. 

You can see a description of the problem that this addresses here: http://stackoverflow.com/questions/14167213/app-engine-django-interleaving-multiple-requests-interfering-in-gae-sessions