This commit is contained in:
2023-04-13 15:42:15 -04:00
parent 54ca1c76c4
commit a010090dba
4 changed files with 134 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
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()