You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
795 B
Python
24 lines
795 B
Python
"""
|
|
Once asyncio has created an event loop,an application registers the functions to call back when a specific event happens:
|
|
as time passes, a file descriptor is ready to be read,or a socket is ready to be written. That type of function is
|
|
called a coroutine. It is a particular type of function that can give back control to the caller so that the event loop
|
|
can continue running.
|
|
"""
|
|
import asyncio
|
|
|
|
# Adding the async keyword makes this a coroutine object
|
|
async def hello_world():
|
|
print('Hello world')
|
|
return 42
|
|
|
|
|
|
hello_world_coroutine = hello_world()
|
|
print(hello_world_coroutine)
|
|
|
|
event_loop = asyncio.get_event_loop()
|
|
try:
|
|
print('Entering the event loop')
|
|
result = event_loop.run_until_complete(hello_world_coroutine)
|
|
print(result)
|
|
finally:
|
|
event_loop.close() |