I am trying to get started learning asyncio, but I can't get simple examples to work. Previous posts about this error point to using a python version prior to 3.7, but here you can see that I'm using the latest build (3.9.4). Entering the code directly into the python interpreter works, but running it from a file will not. Any ideas what I'm doing wrong here?
command line output
> python3 --version
Python 3.9.4
> python3 asyncio.py
Traceback (most recent call last):
File "/home/mmolesworth/courses/asyncio.py", line 22, in <module>
asyncio.run(main())
AttributeError: module 'asyncio' has no attribute 'run'
asyncio.py contents
import asyncio
async def count():
print("One")
await asyncio.sleep(1)
print("Two")
async def main():
await asyncio.gather(count(), count(), count())
if __name__ == "__main__":
import time
s = time.perf_counter()
asyncio.run(main())
elapsed = time.perf_counter() - s
print(f"{__file__} executed in {elapsed:0.2f} seconds.")