Created
March 30, 2024 23:04
-
-
Save normanlmfung/14fc54b5c2dcfbf92f2f2d0b90ed002f to your computer and use it in GitHub Desktop.
python_syntax_asyncio_get_event_loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
async def my_coroutine(): | |
print("Hello,") | |
await asyncio.sleep(1) | |
print("world!") | |
def main(): | |
loop = asyncio.get_event_loop() | |
try: | |
loop.run_until_complete(my_coroutine()) | |
finally: | |
loop.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment