Created
July 2, 2022 07:08
-
-
Save m-root/34e15487db2213254da4f3dac7a96c9d to your computer and use it in GitHub Desktop.
Async exaple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
async def fetch_data(): | |
print('Start Fetching Data') | |
await asyncio.sleep(2) | |
print('Done fetching') | |
return {'Data' : 1} | |
async def print_numbers(): | |
for i in range(10): | |
print(i) | |
await asyncio.sleep(2) | |
async def test_a(): | |
await asyncio.sleep(2) | |
await test_b() | |
async def test_b(): | |
await asyncio.sleep(1) | |
await test_c() | |
async def test_c(): | |
print('test_c') | |
async def main(): | |
task_1 = asyncio.create_task(fetch_data()) | |
task_2 = asyncio.create_task(print_numbers()) | |
# | |
await task_1 | |
await task_2 | |
# await test_a() | |
if __name__ == '__main__': | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment