This commit is contained in:
2023-04-19 19:11:20 -04:00
parent 1ef6c3cbf8
commit 861bd8db11
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()