当我使用@asyncio.coroutine
装饰器在Python3.11.0上运行以下代码时
import asyncio
@asyncio.coroutine # Here
def test():
print("Test")
asyncio.run(test())
我发现了下面的错误:
AttributeError:模块‘异步’没有属性'coroutine‘。你是说:“coroutines”?
据我搜索,@asyncio.coroutine
装饰器用于某些代码。
那么,我如何解决这个错误呢?
发布于 2022-11-07 10:23:08
包含@asyncio.coroutine
装饰器的将从Python3.11中删除,因此asyncio
模块没有@asyncio.coroutine
装饰符,错误是这样写的:
注释:对基于生成器的协同服务的支持被废弃,并在Python3.11中被删除。
因此,您需要在async
关键字之前使用def
,如下所示:
import asyncio
# Here
async def test():
print("Test")
asyncio.run(test()) # Test
然后,您可以解决错误:
Test
https://stackoverflow.com/questions/74345065
复制相似问题