When I ran the code below with @asyncio.coroutine decorator on Python 3.11.0:
import asyncio
@asyncio.coroutine # Here
def test():
print("Test")
asyncio.run(test())
I got the error below:
AttributeError: module 'asyncio' has no attribute 'coroutine'. Did you mean: 'coroutines'?
I find @asyncio.coroutine decorator is used for some code as far as I googled.
So, how can I solve this error?
Generator-based Coroutines which contains @asyncio.coroutine decorator is removed since Python 3.11 so asyncio module doesn't have @asyncio.coroutine decorator as the error says:
Note: Support for generator-based coroutines is deprecated and is removed in Python 3.11.
So instead, you need to use async keyword before def as shown below:
import asyncio
# Here
async def test():
print("Test")
asyncio.run(test()) # Test
Then, you can solve the error:
Test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With