forked from SVIG/python-bootcamp
update
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user