python实现异步调用函数
1 import time 2 from concurrent.futures import ThreadPoolExecutor 3 4 def RunBenchmark(url): 5 print('GET %s' % url) 6 response = url 7 time.sleep(3) 8 return(url+" FINISHED") 9 10 def RunPool(): 11 urls = 'CPU' 12 pool = ThreadPoolExecutor(1) #启动一个线程池 13 task=pool.submit(RunBenchmark, urls) #在另外的线程中运行RunBenchmark() 14 while(not task.done()): #task.done()表示线程池中的工作完成了 15 print("ooo") #主线程中可以执行其他工作 16 time.sleep(0.5) 17 print("bye") 18 19 if __name__ == '__main__': 20 RunPool()
https://www.jianshu.com/p/b9b3d66aa0be
https://blog.csdn.net/sinat_34461756/article/details/83866300
https://cloud.tencent.com/developer/article/1187407
posted on 2019-04-10 18:01 Pentium.Labs 阅读(1553) 评论(0) 编辑 收藏 举报