Created
December 20, 2010 17:39
-
-
Save sahid/748691 to your computer and use it in GitHub Desktop.
Async insert on Google App Engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import logging | |
from google.appengine.ext import db | |
from google.appengine.api import datastore | |
from google.appengine.datastore import datastore_rpc | |
def async_put(entities, **kwargs): | |
config = datastore.CreateConfig(**kwargs) | |
entities, _ = datastore.NormalizeAndTypeCheck(entities, db.Model) | |
entities = [model._populate_internal_entity() for model in entities] | |
conn = datastore_rpc.Connection(adapter=datastore.DatastoreAdapter()) | |
rpcs = conn.async_put(config, entities) | |
if os.environ['SERVER_SOFTWARE'].startswith('Dev'): | |
rpcs.wait() # To execute the request in dev. | |
return rpcs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment