- Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathlesson02_run_task.py
More file actions
Latest commit
22 lines (19 loc) · 531 Bytes
/
Copy pathlesson02_run_task.py
File metadata and controls
22 lines (19 loc) · 531 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# SuperFastPython.com
# example of creating and awaiting an asyncio task
importasyncio
# define a coroutine for a task
asyncdeftask_coroutine():
# report a message
print('executing the task')
# suspend for a moment
awaitasyncio.sleep(1)
# custom coroutine
asyncdefmain():
# report a message
print('main coroutine')
# create and schedule the task
task=asyncio.create_task(task_coroutine())
# wait for the task to complete
awaittask
# start the asyncio program
asyncio.run(main())