【发布时间】:2017-07-24 18:06:01
【问题描述】:
想象一下我有这样的功能:
def func1():
return int(requests.get('https://www.random.org/integers/?num=1&min=0&max=10&col=1&base=10&format=plain&rnd=new').text)
我想调用这个函数三次,对响应求和,然后返回平方和或一些简单的东西。我该怎么做才能使三个函数调用是异步的,但它会等待它们全部返回,就像 JavaScript 中的 Promise.all?
我正在使用 Python 2。
【问题讨论】:
-
为什么不用线程?
-
如果您使用的是 Python 3,您可以使用它的异步功能...在 Python 2 中,您必须使用 threading
标签: python python-2.7 asynchronous