NOTE that if you have an instance (and hence a VM) running, then it has a 
thread that serves incoming requests sequentially as needed.

A new thread is not started for each request, it can be one thread serving 
requests in a loop.

So..... making changes to Thread Local variables (and hence environ, or 
"System Properties" in Java) in one request will affect the state of those 
thread variables for subsequent requests.

Thus, if you want a known, "sane", state - you need to reset such thread 
local variables at the start or end of each request (either in servlet 
code) or in a filter...

We found bugs due to one request modifying a thread local variable, and a 
later request (server by same instance and VM...) picking it up...

On Wednesday, 29 August 2012 01:15:29 UTC+2, Kyle Finley wrote:
>
> According to Nick Johnson (a former App Engine team member) os.environ is 
> threadsafe:
>
> But what if my app makes use of 'os.environ' or other CGI-isms, you ask? 
> All is not lost. The smart folks on the Python 2.7 runtime team foresaw 
> that some apps will inevitably do this, and built in a workaround for them. 
> 'os.environ' and a few other bits and pieces are now "thread local" on the 
> 2.7 runtime, meaning that each thread (and hence each request) see a 
> different copy of them, containing only the data relevant to the current 
> request. Apps that expect to get request information from os.environ can 
> thus continue to work fine. Bear in mind that this really is a workaround, 
> though - it's definitely cleaner to rewrite your apps to rely only on the 
> WSGI environment, if you have the opportunity. The WSGI environment can be 
> accessed as self.request.environ if you're using webapp.
>
> http://blog.notdot.net/2011/10/Migrating-to-Python-2-7-part-1-Threadsafe
>
> I don't know if it is documented anywhere else, I suspected it is.
>
> - Kyle
>
> On Tuesday, August 28, 2012 4:30:16 PM UTC-5, 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/-/AK-FrQBXZUsJ.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to