上一页 1 2 3 4 5 6 7 8 ··· 49 下一页
摘要: ''' concurrent.futures 模块提供异步执行可调用对象高层接口,使用线程池 ThreadPoolExecutor 或 进程池 ProcessPoolExecutor 来实现异步。目的是保证服务稳定运行的前提下提供最大的并发能力。 ''' from concurrent.future 阅读全文
posted @ 2023-03-31 09:21 LeoShi2020 阅读(15) 评论(0) 推荐(0) 编辑
摘要: import asyncio from asyncio import Future async def f1(): print(1) await asyncio.sleep(3) print(2) return "f1" def callback(f: Future): f.get_loop().s 阅读全文
posted @ 2023-03-31 09:09 LeoShi2020 阅读(31) 评论(0) 推荐(0) 编辑
摘要: import asyncio from functools import partial from asyncio import Future async def f1(): print(1) await asyncio.sleep(2) print(2) return "f1" def callb 阅读全文
posted @ 2023-03-30 19:20 LeoShi2020 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 相同点: 从功能上看, asyncio.wait 和 asyncio.gather 实现的效果是相同的。 不同点: 使用方式不一样,wait需要传一个可迭代对象,gather传多个元素 wait比gather更底层,gather可以直接得到结果,wait先得到future再得到结果 wait可以通过 阅读全文
posted @ 2023-03-30 17:25 LeoShi2020 阅读(103) 评论(0) 推荐(0) 编辑
摘要: import asyncio async def f1(): print(1) await asyncio.sleep(2) print(2) async def f2(): print(3) await asyncio.sleep(2) print(4) async def main(): pri 阅读全文
posted @ 2023-03-30 16:54 LeoShi2020 阅读(22) 评论(0) 推荐(0) 编辑
摘要: import asyncio import aiohttp async def download_img(session, url): file_name = url.rsplit('/')[-1] print(f"下载图片:{file_name}") await asyncio.sleep(2) 阅读全文
posted @ 2023-03-30 15:59 LeoShi2020 阅读(19) 评论(0) 推荐(0) 编辑
摘要: import asyncio async def f1(): print(1) await asyncio.sleep(2) print(2) async def f2(): print(3) await asyncio.sleep(2) # 等 可以等待的对象 print(4) tasks = [ 阅读全文
posted @ 2023-03-30 15:35 LeoShi2020 阅读(14) 评论(0) 推荐(0) 编辑
摘要: from fastapi import FastAPI from fastapi.responses import RedirectResponse app = FastAPI() @app.get("/") def go_to_baidu(): return RedirectResponse("h 阅读全文
posted @ 2023-03-30 14:21 LeoShi2020 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 1. StreamingResponse支持文件类型的操作 from fastapi import FastAPI from fastapi.responses import StreamingResponse app = FastAPI() @app.get("/") def index(): d 阅读全文
posted @ 2023-03-30 14:20 LeoShi2020 阅读(328) 评论(0) 推荐(0) 编辑
摘要: 1.PlainTextResponse用来响应纯文本的数据 from fastapi import FastAPI from fastapi.responses import PlainTextResponse app = FastAPI() @app.get("/", response_class 阅读全文
posted @ 2023-03-30 14:18 LeoShi2020 阅读(84) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 49 下一页