<p>尝试清除上下文缓存中的内容。在</p>
<pre><code>from google.appengine.ext import ndb
context = ndb.get_context()
context.clear_cache()
</code></pre>
<p><a href="https://cloud.google.com/appengine/docs/python/ndb/cache#incontext" rel="nofollow">See documentation here</a></p>
<blockquote>
<p>With executing long-running queries in background tasks, it's possible
for the in-context cache to consume large amounts of memory. This is
because the cache keeps a copy of every entity that is retrieved or
stored in the current context. To avoid memory exceptions in
long-running tasks, you can disable the cache or set a policy that
excludes whichever entities are consuming the most memory.</p>
</blockquote>
<p>您也可以尝试清除webapp2响应对象缓冲区。在循环</em>之前插入这行代码</p>
^{pr2}$
<blockquote>
<p>The response buffers all output in memory, then sends the final output
when the handler exits. webapp2 does not support streaming data to the
client. The clear() method erases the contents of the output buffer,
leaving it empty.</p>
</blockquote>
<p><a href="http://webapp-improved.appspot.com/guide/response.html#" rel="nofollow">Check this link</a></p>