【问题标题】:TypeError in await asyncio.sleep ('dict' object is not callable)等待 asyncio.sleep 中的 TypeError('dict' 对象不可调用)
【发布时间】:2019-01-21 22:16:30
【问题描述】:

我最近开始使用python,在我的aiohttp服务器上收到以下错误日志:

ERROR:app.handlers.socket_handler:'dict' object is not callable
Traceback (most recent call last):
  File "[...]/app/handlers/socket_handler.py", line 47, in try_coroutine
    await coroutine
  File "[...]/app/handlers/socket_handler.py", line 65, in do_stuff
    async for data in stuff_repo.observe_stuff(search=param_search):
  File "[...]/app/repositories/stuff_repository.py", line 74, in observe_stuff
    await asyncio.sleep(sleep_for)
TypeError: 'dict' object is not callable

这对我来说没有任何意义,因为在任何时候都没有dict 对象或callables 参与asyncio.sleep 调用,而sleep_for 是一个值为30 的int,绝对不是已修改,只读:

代码有什么问题?

【问题讨论】:

  • 你必须粘贴你的代码,但从给定的消息中,我只能理解你做了一个字典分配给 asyncio.sleep,覆盖了函数。 (一行如asyncio.sleep = {}
  • 不,整个项目中没有分配给 asyncio.sleep。我不知道它是否相关,但我很确定这只发生在我使用 PyCharm 调试(放置断点)时。要么那个,要么我只是偏执。
  • 您是否将某个模块命名为 asyncio.py 或周围有一个?
  • 不行,项目上没有同名模块,直接这样导入:import asyncio

标签: python python-3.x typeerror python-asyncio aiohttp


【解决方案1】:

这是一个 PyCharm 错误,因为它仅在已调试时添加断点时引起。

修复: 添加环境变量PYDEVD_USE_FRAME_EVAL=NO

来源:

Debugging asyncio code in PyCharm causes absolutely crazy unrepeatable errors

https://youtrack.jetbrains.com/issue/PY-25856

【讨论】:

    猜你喜欢
    • 2011-10-01
    • 2012-10-31
    • 2019-02-27
    • 2017-05-27
    • 2020-03-24
    • 2016-03-07
    • 2019-08-10
    • 1970-01-01
    相关资源
    最近更新 更多