Andrey Fedorov
Andrey Fedorov

Reputation: 9699

Running remote_api_shell.py with gevent

I have a relatively simple script I use to run map jobs over my data, and I'd like it to run a faster by using gevent to make reads from the datastore non-blocking.

I tried adding gevent.monkey.patch_socket() to the top of remote_api_shell.py, but after I log in, it throws a urllib2.URLError (traceback).

I'm new to both GAE and gevent. Is there an easier way to accomplish what I'm trying to do? Could someone point me in the right direction to get this working?

Upvotes: 0

Views: 236

Answers (1)

bossylobster
bossylobster

Reputation: 10164

If using ndb:

You can use ndb with *_async datastore operations:
https://developers.google.com/appengine/docs/python/ndb/async

For example, to retrieve a list of elements by key:

ndb.get_multi_async(list_of_keys)

The great thing with ndb is that every datastore operation on keys or entities has an async equivalent.

If using db:

You can use the Async Datastore API.

For example, to retrieve a list of elements by key:

from google.appengine.ext import db
db.get_async(list_of_keys)

Where list_of_keys contains elements that are either strings, instances of google.appengine.api.datastore_types.Key, or instances of google.appengine.api.datastore.Entity.

Similarly you can use db.put_async on lists of entities and db.delete_async on lists similar to those for db.get_async.

Upvotes: 1

Related Questions