python - BaseEventLoop.run_in_executor() 抛出 "unexpected keyword argument ' 回调'"从 Python 3.5 开始

标签 python python-asyncio python-3.5

我正在通过默认的 asyncio 事件循环运行函数 provision_ec2_node() thread executor 。该函数接受许多参数,我通过 functools.partial() 传递给执行器。

task = loop.run_in_executor(
    executor=None,
    callback=functools.partial(
        provision_ec2_node,
        modules=modules,
        host=instance.ip_address,
        identity_file=identity_file,
        cluster_info=cluster_info))

这段代码在 Python 3.4 上运行良好,我已经这样使用了几个月了。

但是,我最近升级到了 Python 3.5,现在上面的代码抛出了这个错误:

TypeError: run_in_executor() got an unexpected keyword argument 'callback'

查看Python 3.5 release notes concerning asyncio ,我没有看到任何可以解释这种行为变化的内容。此外,3.5 文档 still say functools.partial() 是将带有关键字的函数传递给执行器的正确方法。

什么给出了?

最佳答案

显然第二个参数是 renamedcallbackfunc但更改未反射(reflect)在文档中 截至 2015 年 10 月 1 日,更改已反射(reflect)在文档中。这就是它失败的原因。

要么将其更新为新名称(并失去 Python <3.5 兼容性),要么将参数作为位置参数传递:

task = loop.run_in_executor(None, functools.partial(...))

关于python - BaseEventLoop.run_in_executor() 抛出 "unexpected keyword argument ' 回调'"从 Python 3.5 开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32873974/

相关文章:

VS 2015 中的 Python IntelliSense/代码完成

python - 记录异步调用的正确/常用方法

python - 在其他函数中使用 Split 参数

python - TensorFlow 的 TensorBoard 不显示事件图

Python websockets 服务器和 websockets 客户端在运行两个任务时使用 asyncio 断言错误

python - 如何在 Python 中异步接收来自多个 WebSocket 的数据?

python - Pyinstaller:导入错误:DLL加载失败:找不到指定的模块

python - 在 CSV 中写入时定位 numpy 矩阵和数组

python - Boto3 和 AWS Lambda - 删除早于

python - 异步函数不异步工作