asyncio python包协程报错

问题描述 投票:0回答:0

我无法在另一个异步函数中调用异步函数。显示运行时错误。

RuntimeWarning: coroutine 'on_get' was never awaited
handle = None  # Needed to break cycles when an exception occurs.
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

所以我在新的python框架中开发了一个CRUD操作API,叫做Robyn。我已经为我可以检索、创建、更新和删除的所有四种操作开发了四个端点,以及一个可以同时执行所有四种操作的端点。

所以Robyn支持异步函数。我正在尝试调用可以执行所有操作的函数内的每个函数。但是相反,我收到了 RuntimeError。

@app.get("/") # Retrieve
async def on_get(request):
    result = await asyncio.create_task(Retrieve())
    return result
@app.get("/:opt/values")
async def on_dynm(request):

    que = request['queries']
    opt = str.lower(request['params']['opt'])
    
    if opt == "create":
        result = asyncio.run(on_post(request))
    elif opt == "update":
        name = que['name']
        NewName = que['NewName']        
        result = asyncio.run(on_put(name,NewName))
    elif opt == "delete":
        name = que['name']
        result = asyncio.run(on_delete(request))
    else:
        result = await asyncio.run(on_get(request))
  
    return result
python frameworks python-asyncio
© www.soinside.com 2019 - 2024. All rights reserved.