Seeking enlightenment - global variables in AppEngine (aeoid.get_current_user())

Posted by jerd on Stack Overflow See other posts from Stack Overflow or by jerd
Published on 2010-03-20T06:49:31Z Indexed on 2010/03/20 7:01 UTC
Read the original article Hit count: 589

Hello

This may be a 'Python Web Programming 101' question, but I'm confused about some code in the aeoid project (http://github.com/Arachnid/aeoid). here's the code:

_current_user = None

def get_current_user():
    """Returns the currently logged in user, or None if no user is logged in."""
    global _current_user

    if not _current_user and 'aeoid.user' in os.environ:
        _current_user = User(None, _from_model_key=os.environ['aeoid.user'])
    return _current_user

But my understanding was that global variables were, ehm, global! And so different requests from different users could (potentially) access and update the same value, hence the need for sessions, in order to store per-user, non-global variables. So, in the code above, what prevents one request from believing the current user is the user set by another request? Sorry if this is basic, it's just not how i thought things worked.

Thanks

© Stack Overflow or respective owner

Related posts about google-app-engine

Related posts about python