How*_*ame 3 cx-oracle python-3.x async-await python-asyncio aiohttp
我正在从烧瓶转移到 aiohttp,我需要在不支持异步的 Oracle 数据库中执行一些查询。所以我想知道如何在 aiohttp 中做到这一点?
这个怎么样?
或者还有其他(正确的)方法来做到这一点?
提前致谢!
该loop.run_in_executor协程正是这么做的:
result = await loop.run_in_executor(executor, sync_fn, *args)
Run Code Online (Sandbox Code Playgroud)
使用您的示例:
executor = ThreadPoolExecutor(max_workers=1)
async def hello(request):
param1, param2 = get_params(request)
result = await app.loop.run_in_executor(executor, sync_fn, param1, param2)
return web.Response(text=result)
Run Code Online (Sandbox Code Playgroud)