python - Managed VM Background thread loses environment -


i having problems using background threads in managed vm in google app engine.

i getting callbacks library linked via ctypes need executed in background explaining in previous question.

the problem is: application loses execution context (wsgi application) , missing environment variables application id. without cannot make calls database fail.

i call background thread like

background_thread.start_new_background_thread(saveitemstodatabase, []) 

is there way copy environment background thread or maybe execute task in different context?

update: traceback makes clear problem is:

_todatastoreerror(err)google.appengine.api.datastore_errors.badrequesterror: application id (app) format invalid: '_' 

application context thread local in appengine when created through standard app handler. remember applications in appengine run in python27 thread enabled have threads. each wsgi call environment variables has thread local, or information leak between handled requests.

this means additional threads create need passed app context explicitly.

in fact when start reading docs on background threads pretty clear going on, https://cloud.google.com/appengine/docs/python/modules/#python_background_threads - a background thread's os.environ , logging entries independent of of spawning thread.

so have copy env (os.environ) or parts need , pass thread arguments. problem may not limited appid may find thats first thing missing. instance if use namespaces.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -