import asyncio import traceback from concurrent.futures import ThreadPoolExecutor, as_completed
import aiohttp
classT:
asyncdefget(self, index): asyncwith aiohttp.ClientSession() as session: for j in range(10): asyncwith session.get("http://www.baidu.com") as r: t = await r.text() print(index)
test = T()
defmain(index): asyncio.run(test.get(index))
if __name__ == '__main__': task_list = [] pools = ThreadPoolExecutor(5) for i in range(5): task_list.append(pools.submit(main, i))
# 阻塞主进程 for result in as_completed(task_list): data = result.result()
import asyncio import traceback from concurrent.futures import ThreadPoolExecutor, as_completed
import aiohttp
classT:
asyncdefget(self, index): asyncwith aiohttp.ClientSession() as session: for j in range(10): asyncwith session.get("http://www.baidu.com") as r: t = await r.text() print(index)
import asyncio import traceback from concurrent.futures import ThreadPoolExecutor, as_completed
import aiohttp
classT:
asyncdefget(self, index): asyncwith aiohttp.ClientSession() as session: for j in range(10): asyncwith session.get("http://www.baidu.com") as r: t = await r.text() print(index)