# appengine

Published articles for appengine.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Compare-And-Set in Memcache

DevFeed: [Compare-And-Set in Memcache](<https://devfeed.tech/articles/compare-and-set-in-memcache-38892.md>)

Original publisher: [Read original article](<http://neopythonic.blogspot.com/2011/08/compare-and-set-in-memcache.html>)

Author: Guido van Rossum (noreply@blogger.com)

Published: 2011-08-25T16:59:00Z

Content type: tutorial

Language: en

Sources: [Guido van Rossum](<https://devfeed.tech/sources/guido-van-rossum.md>)

Topics: [content addressed store](<https://devfeed.tech/topics/content-addressed-store.md>), [Python](<https://devfeed.tech/topics/python.md>), [bug](<https://devfeed.tech/topics/bug.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [algorithms](<https://devfeed.tech/tags/algorithms.md>), [appengine](<https://devfeed.tech/tags/appengine.md>), [cas](<https://devfeed.tech/tags/cas.md>), [code](<https://devfeed.tech/tags/code.md>), [compare](<https://devfeed.tech/tags/compare.md>), [google](<https://devfeed.tech/tags/google.md>), [memcache](<https://devfeed.tech/tags/memcache.md>), [new-feature](<https://devfeed.tech/tags/new-feature.md>), [python](<https://devfeed.tech/tags/python.md>), [race-condition](<https://devfeed.tech/tags/race-condition.md>)

### AI overview

This tutorial explains Compare-And-Set in memcache, including its atomic update use case and how it prevents lost updates caused by race conditions when concurrent requests modify the same key.

### Source excerpt

With the most recent release (1.5.3, last week) App Engine's Python API for Memcache has added a new feature, Compare-And-Set. This feature (with a different API) was already available in Java; it has also been available in the non-App-Engine pure-Python memcache client. In fact, I designed the App Engine Python API for this feature to be compatible with the latter, since most of the rest of the App Engine Python API also strives to be at least a superset of that package. But what is it? There seems to be little information on how to use Compare-And-Set with memcache. It is also sometimes (incorrectly) referred to as Compare-And-Swap -- incorrect, because the cas() operation does not actually "swap" anything. The first response when we closed the bug requesting this feature was "Some examples of usage are appreciated." So here goes. The basic use case for Compare-And-Set is when multiple requests that are being handled concurrently need to update the same memcache key in an atomic fashion. Let's assume you are managing a counter in memcache. (Actually, you could use the incr() and decr() operations to update 64-bit integer counters atomically, but just for argument's sake assume you cannot use those -- there are other data types for which the memcache service does not have built-in support.) The naive code to update a counter would be something like this: def init_counter(key): . memcache.set(key, 0) def bump_counter(key): . counter = memcache.get(key) . assert counter is not None, 'Uninitialized counter' . memcache.set(key, counter+1) (Aside: I don't want to have to think about how to get blogger to properly format Python code. I really don't. So just bear with the dots I use for indentation. Okay? Comments pointing me to solutions will be DELETED.) (Aside 2: The assert is kind of naive; in practice you'll have to somehow deal with counter initialization. You also should implement a backup for your counter using the App Engine datastore, so that it can survive evic

## Asynchronous RPC in App Engine Today

DevFeed: [Asynchronous RPC in App Engine Today](<https://devfeed.tech/articles/asynchronous-rpc-in-app-engine-today-38888.md>)

Original publisher: [Read original article](<http://neopythonic.blogspot.com/2011/01/asynchronous-rpc-in-app-engine-today.html>)

Author: Guido van Rossum (noreply@blogger.com)

Published: 2011-01-24T18:07:00Z

Content type: tutorial

Language: en

Sources: [Guido van Rossum](<https://devfeed.tech/sources/guido-van-rossum.md>)

Topics: [Remote Procedure Call (RPC)](<https://devfeed.tech/topics/rpc.md>), [SDKs](<https://devfeed.tech/topics/sdks.md>), [client library](<https://devfeed.tech/topics/client-library.md>), [servers](<https://devfeed.tech/topics/servers.md>)

Tags: [appengine](<https://devfeed.tech/tags/appengine.md>), [asynchronous](<https://devfeed.tech/tags/asynchronous.md>), [client-library](<https://devfeed.tech/tags/client-library.md>), [fetch](<https://devfeed.tech/tags/fetch.md>), [python](<https://devfeed.tech/tags/python.md>), [rpc](<https://devfeed.tech/tags/rpc.md>), [sdk](<https://devfeed.tech/tags/sdk.md>)

### AI overview

This article introduces low-level asynchronous RPC support in Google App Engine. It demonstrates sending requests to multiple remote service instances with urlfetch and using UserRPC.wait_any() to return the first completed result, while noting how to handle subsequent results and outstanding requests.

### Source excerpt

While I was laying the groundwork for a new datastore client library with support for asynchronous requests, I added some low-level support for asynchronous RPCs that you can use today. The only App Engine API with documented support for asynchronous RPCs is urlfetch, and it happens to be quite useful with that. Suppose you want to fetch some data from a remote service. The remote service has two instances, both of which are slightly flaky. What you want to do is send off requests to both servers simultaneous (this is the easy part) and then wait for the first one to give you a result. The latter uses the new API that I'm about to describe here. from google.appengine.api import urlfetch, apiproxy_stub_map urls = ['http://service1.com', 'http://service2.com'] # Etc. rpcs = [] for url in urls: rpc = urlfetch.create_rpc(deadline=1.0) urlfetch.make_fetch_call(rpc, url) rpcs.append(rpc) rpc = apiproxy_stub_map.UserRPC.wait_any(rpcs) # Now rpc is the first rpc that returned a result. Have at it! That's all! If you're interested in learning more about this handy class method, just check out its docstring in the App Engine SDK. Note that technically you should loop until it doesn't return None. You can also repeatedly call wait_any() to get subsequent result. Make sure to remove the rpc it returns (if any) from the list, since otherwise it will return the same rpc over and over again: the specification of wait_any() says it returns the first rpc in the given list that completes, regardless of whether you have seen it before. Also note that there currently is no way to cancel the other RPCs, which is why I passed a low deadline to the create_rpc() call. The problem is that even if you completely ignore the other RPCs, the App Engine runtime still waits for them to finish or timeout. Finally, there is also a similar class method UserRPC.wait_all(), which waits until all RPCs in the list you pass it are complete. (It doesn't return anything.) PS. Don't look too closely at the

## A new App Engine datastore API

DevFeed: [A new App Engine datastore API](<https://devfeed.tech/articles/a-new-app-engine-datastore-api-38889.md>)

Original publisher: [Read original article](<http://neopythonic.blogspot.com/2011/01/new-app-engine-datastore-api.html>)

Author: Guido van Rossum (noreply@blogger.com)

Published: 2011-01-07T20:20:00Z

Content type: release

Language: en

Sources: [Guido van Rossum](<https://devfeed.tech/sources/guido-van-rossum.md>)

Topics: [Python](<https://devfeed.tech/topics/python.md>), [API](<https://devfeed.tech/topics/api.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [Open Source](<https://devfeed.tech/topics/open-source.md>), [generators](<https://devfeed.tech/topics/generators.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [appengine](<https://devfeed.tech/tags/appengine.md>), [classes](<https://devfeed.tech/tags/classes.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [design](<https://devfeed.tech/tags/design.md>), [generators](<https://devfeed.tech/tags/generators.md>), [kind](<https://devfeed.tech/tags/kind.md>), [open-source](<https://devfeed.tech/tags/open-source.md>), [python](<https://devfeed.tech/tags/python.md>)

### AI overview

Guido van Rossum introduces Datastore Plus, a preliminary redesign of the Python datastore API for App Engine users. The proposal includes cleaner Key, Model, Property, and Query implementations and a high-level asynchronous API using Python generators as coroutines. The implementation is available as an open-source project for review, with feedback requested on its documentation, implementation, and API design.

### Source excerpt

This post is primarily intended for App Engine users (and of those, only Python users :-). Over the past months I've been working on a new design for the Python datastore API, under the code name Datastore Plus. The new design is very ambitious, and changes a lot of things: New, cleaner implementations of Key, Model, Property and Query classes High-level asynchronous API using Python generators as coroutines (PEP 342) The design is meant to eventually replace the existing db package in the App Engine runtime library, but for now, it is just an open source project which you have to download and copy into your application. I am not at all finished with this design, but I believe in listening to users, so I am making a preliminary version of the new API available for review. Please send me your thoughts, either in this blog, or via private mail to guido (at) google.com. Note that the implementation works, but I cannot guarantee that it won't change. Documentation is here: http://goo.gl/D6Onw The project to check out is here: http://goo.gl/GapXI You must use Mercurial to check out the project, but it's fine to check it out anonymously -- I don't require anybody to log in to look or comment. (If using Mercurial is too much of a burden, there's also a zipfile on the site, but I don't plan to update it frequently.) I'm interested in receiving any kind of feedback at all. It would help me if you could clarify whether your feedback is about an issue with the documentation, an issue with the implementation, or an issue with the API design -- though I realize you can't always tell the difference. :-) (You can also comment on the thread in the google-appengine-python group here: https://groups.google.com/group/google-appengine-python/browse_thread/thread/454cb81d49e759f2.)

## Review of Using Google App Engine by Charles Severance

DevFeed: [Review of Using Google App Engine by Charles Severance](<https://devfeed.tech/articles/new-app-engine-book-38882.md>)

Original publisher: [Read original article](<http://neopythonic.blogspot.com/2009/06/new-app-engine-book.html>)

Author: Guido van Rossum (noreply@blogger.com)

Published: 2009-06-15T16:20:00Z

Content type: opinion

Language: en

Sources: [Guido van Rossum](<https://devfeed.tech/sources/guido-van-rossum.md>)

Topics: [Web Development](<https://devfeed.tech/topics/web-development.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Python](<https://devfeed.tech/topics/python.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [CSS](<https://devfeed.tech/topics/css.md>), [HTML](<https://devfeed.tech/topics/html.md>), [Caching](<https://devfeed.tech/topics/caching.md>), [Ajax](<https://devfeed.tech/topics/ajax.md>)

Tags: [ajax](<https://devfeed.tech/tags/ajax.md>), [appengine](<https://devfeed.tech/tags/appengine.md>), [book](<https://devfeed.tech/tags/book.md>), [book-review](<https://devfeed.tech/tags/book-review.md>), [caching](<https://devfeed.tech/tags/caching.md>), [css](<https://devfeed.tech/tags/css.md>), [google](<https://devfeed.tech/tags/google.md>), [html](<https://devfeed.tech/tags/html.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [python](<https://devfeed.tech/tags/python.md>), [web](<https://devfeed.tech/tags/web.md>)

### AI overview

A review of Charles Severance's book Using Google App Engine, describing it as an introductory resource for web programming and App Engine. The book covers enough HTML, CSS, Python, and JavaScript to help beginners create dynamic websites, including datastore models, forms, simple AJAX patterns, caching, and debugging, while directing readers to other resources for deeper study.

### Source excerpt

At Google I/O I received a copy of Using Google App Engine by Charles Severance, published by O'Reilly. I haven't kept track, but this appears one of the first App Engine books to actually hit the stores -- an Amazon search for App Engine showed up one other book (Developing with Google App Engine by Eugene Ciara, published by APress) and many titles available for pre-order (including additional titles from the same publishers). Severance's book is a quick read if you're already familiar with the basic premises of web programming. I think it would do well in an introductory course about the topic. (The author teaches at the University of Michigan so this is likely how he developed the material in the first place.) In fact, quite a bit of the book could well have come from a pre-existing earlier course: the chapters on HTML, CSS, Python and JavaScript barely mention App Engine. Don't get me wrong, I think that's a good approach: in my experience quite a few App Engine users are new to web programming in general, or could at least use a refresher course. If you don't fall in this category, don't feel offended: you just probably aren't the intended audience for this book. On the other hand, if you've developed for the web but haven't used Python before, you could probably just skip the HTML/CSS chapter and dive right into Python and App Engine. If you're a blank sheet where it comes to programming, don't expect to come out an experienced Python developer: the book only covers enough of the language so you can get started with App Engine without feeling you're just copying and pasting text. The same is actually true for any topic covered -- in many cases the book actually recommends that you study a topic more in-depth using other resources. But in each case the book's coverage is enough to get you started with the creation of dynamic web sites, and that's the important part. After all, you didn't learn your mother tongue by studying the rules of grammar either: you lea