In the python27 runtime, os.environ is thread safe since it is implemented 
as request/thread-local. However, this means that changes in one request 
will not be visible by other requests. Also, since os.environ is 
conceptually a global dictionary, I would recommend against writing to it 
whenever possible. If you need to access request data, you should be 
reading from the first positional parameter passed to the WSGI application 
when it is invoked.

Regarding the relationship between the WSGI environ and os.environ, there 
is no direct relationship specified in PEP333. What PEP333 says is:
The environ parameter is a dictionary object, containing CGI-style 
environment variables....

In addition to the CGI-defined variables, the environ dictionary *may* also 
contain arbitrary operating-system "environment variables"...

Finally, some applications, frameworks, and middleware may wish to use the 
environ dictionary to receive simple string configuration options. Servers 
and gateways *should* support this by allowing an application's deployer to 
specify name-value pairs to be placed in environ. In the simplest case, 
this support can consist merely of copying all operating system-supplied 
environment variables from os.environ into the environ dictionary, since 
the deployer in principle can configure these externally to the server, or 
in the CGI case they may be able to be set via the server's configuration 
files.

This last case we handle by supporting specifying environment variables in 
app.yaml.

On Wednesday, 29 August 2012 07:30:16 UTC+10, Jason Collins wrote:
>
> The top answer in this SO thread suggests that os.environ should be 
> generally avoided because it's not threadsafe in the threadsafe: truePython 
> 2.7 environment.
>
>   
> http://stackoverflow.com/questions/5901653/name-of-current-app-in-google-app-engine-python
>   
>
> I'm dubious because the WSGI spec explicitly uses os.environ to construct 
> its request objects, etc.
>
> Can anyone confirm/deny the safety of using os.environ in a threadsafe: 
> true deployment?
>
> Thanks,
> j
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/MLNFNxrQxzMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to