python asyncio REST api 调用给出错误

标签 python multithreading python-multithreading python-asyncio

我正在尝试使用 asyncio 异步调用 REST API,但我不断收到错误“coroutine was never waitinged”,我明白。但我想要这种行为,我希望我的函数通过发布而不是等待结果来结束。这是我的代码

async def callCoroutine:
    #call a REST API 

def lambda_handler(event, context):   
    loop = asyncio.get_event_loop()
    task = loop.create_task(callCoroutine(data))
    return

有人可以帮忙吗?

最佳答案

如果只需要调用API,不考虑结果,可以在另一个线程中使用Executor,不会阻塞主线程。

要在执行器中运行,请使用 AbstractEventLoop.run_in_executor()concurrent.futures 的执行者.

关于python asyncio REST api 调用给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51674786/

相关文章:

python - 索引错误 : list index out of range while webscraping advertisements with beautifulsoup

c++ - 在 Linux/C++ 中,发送到线程/进程的信号是否使其变为事件状态?

java - Spring beans 中处理线程安全的方法及其优缺点

python - 套接字P2P和线程

python - 在 Flask 应用程序的后台运行一个 scrapy 蜘蛛

python - 在 Django 中获取项目特定应用程序列表

python - 检查列表的元素是否包含另一个列表的所有元素的有效方法

c - 子线程中的 malloc 占用太多虚拟内存

python - 线程已完成的进程永远不会退出

python - Print() 被忽略