Starting from Python 3.7 awaitable coroutines can be easily called with asyncio.run()
method:
1>>> import asyncio
2
3>>> async def main():
4... print('hello')
5... await asyncio.sleep(1)
6... print('world')
7
8>>> asyncio.run(main())
9hello
10world
As you know, similar code in Python 3.6 looks like:
1>>> import asyncio
2
3>>> async def main():
4... print('hello')
5... await asyncio.sleep(1)
6... print('world')
7
8>>> loop = asyncio.get_event_loop()
9>>> loop.run_until_complete(main())
10hello
11world
12>>> loop.close()
One more step to real asynchronous code.