如下所示:
import time,requestesfrom tomorrow import threads@threads(10)#使用装饰器,这个函数异步执行def download(url): return requests.get(url)def main(): start = time.time() urls = [ 'https://pypi.org/project/tomorrow/0.2.0/', 'https:///infodetail-1028793.html?yyue=a21bo.50862.201879', ] responses = [download(i) for i in urls] end = time.time() print("Time: %f seconds" % (end - start))if __name__=="__main__": main()不使用多线程:
使用多线程:
以上这篇python使用tomorrow实现多线程的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。