17 lines
425 B
Python
17 lines
425 B
Python
import asyncio
|
|
|
|
# Define a coroutine function
|
|
async def greet(name):
|
|
print(f"Hello, {name}!")
|
|
await asyncio.sleep(1)
|
|
print(f"Goodbye, {name}!")
|
|
|
|
# Call the coroutine function
|
|
coroutine_obj = greet("Karen")
|
|
|
|
# coroutine_obj is a coroutine object, not the actual execution of the coroutine
|
|
|
|
# Use an event loop to run the coroutine
|
|
loop = asyncio.get_event_loop()
|
|
loop.run_until_complete(coroutine_obj)
|
|
loop.close() |