在谷歌应用引擎中异步读取URL



假设我在谷歌应用程序引擎中有以下代码:

from urllib import urlopen
...
data1 = urlopen(url2).read()
data2 = urlopen(url2).read()
...

为了提高延迟,我想异步运行这两个对外部URL的请求。我该怎么做?我知道如何在普通Python中使用线程池来实现这一点,但谷歌应用程序引擎似乎不支持多个线程。

你读过文档吗?https://developers.google.com/appengine/docs/python/urlfetch/asynchronousrequests

您应该使用ndb tasklets。

https://developers.google.com/appengine/docs/python/ndb/async#urlfetch

最新更新