2

When running a Python Web Application on App Engine, we need to set up some mechanism to execute some code before (or during) the application's initialization. This means that, in the optimal solution, the code that we need to run is executed as early as possible. The purpose of this is to allow for the App Engine remote_api to be initialized before the local datastore is accessed, so as to prevent datastore access conflicts.

This is a very rough example of what we're looking for:

imports (including remote_api)

def some_initialization_function_or_similar (args):
    some_init_function_calls(...)

    setup_remote_api(...)

    access_datastore_the_first_time(...)

Please take this question as reference to the scenario we're looking at: Using GAE remote api for debugging from localhost - Connecting too late?

3
  • Why do you need this? Understanding the use case beyond a reference to separate abstract situation may be helpful and may lead to other ideas that don't need this type of solution. Checking out the source (code.google.com/p/googleappengine/source/browse/trunk/python/…) may help as well. Commented Oct 8, 2012 at 20:27
  • @bossylobster We need this to have a set-up which uses the remote_api for local database access, to help us debug some use cases where it would be otherwise too expensive or difficult to do. We already have tested remote api functions, so we can retrieve data from the remote datastore, but when writing data to the response of the WSGI application, we get an error which we believe has to do with datastore conflict. Commented Oct 9, 2012 at 15:06
  • If you want to inspect the local datastore, navigate to http://localhost:PORT/_ah/admin/interactive where PORT is the port you are using for your local app server. You can execute arbitrary code there against the application. Commented Oct 10, 2012 at 1:43

1 Answer 1

3

Assuming you have a single entry point (== script named in app.yaml) you can just call the desired code after your imports but before you call your main() function. This means it will be run only when the main script is being imported, which is only on the first request (hitting that entry point).

If you have multiple entry points, try putting it in appengine_config.py. That gets loaded pretty early.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, Guido. Where is appengine_config.py located?
In the root of your application.
When I add the remote api initialization code to appengine_config.py, I get this error: File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_blobstore.py", line 79, in GetBlobStorage return apiproxy_stub_map.apiproxy.GetStub('blobstore').storage AttributeError: 'RemoteStub' object has no attribute 'storage'
Possibly stackoverflow.com/questions/12413826/… can help with that message?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.