python - Is threading.local() a safe way to store variables for a single request in Google AppEngine? -


i have google appengine app want set global variable request only. can this?

in request_vars.py

# request_vars.py  global_vars = threading.local() 

in another.py

# another.py  request_vars import global_vars get_time():     return global_vars.time_start 

in main.py

# main.py  import request_vars import global_vars  global_vars.time_start = datetime.datetime.now()  time_start = another.get_time() 

questions: considering multithreading, concurrent requests, building on google appengine, , hundreds (even thousands) of requests per second, value of time_start equal value set in global_vars.time_start in main.py per request? safe use multithreading/threadsafe enabled?

yes, using threading.local excellent method set per-request global. request handled 1 thread, on 1 instance in google cloud. thread local value unique thread.

take account thread can reused future requests, , reset value @ start of request.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -