From 61e7a886c889a886f0c0716c54cc786ee8edf719 Mon Sep 17 00:00:00 2001
From: Philipp Theyssen
Date: Mon, 9 Sep 2024 20:49:23 +0200
Subject: [PATCH] Make request async
---
echo.py | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/echo.py b/echo.py
index 1c58b3a..6c0d9e9 100644
--- a/echo.py
+++ b/echo.py
@@ -1,17 +1,20 @@
import sys
import requests
+import asyncio
from rich.console import Console
from rich.markdown import Markdown
console = Console()
-def main():
+async def main():
+ loop = asyncio.get_event_loop()
args = sys.argv[-1]
- resp = requests.get(args)
- console.print(Markdown(resp.text))
+ resp = await loop.run_in_executor(None, requests.get, args)
+ console.print(Markdown(str(resp.content)))
+ print("async request going on")
if __name__ == "__main__":
- main()
+ asyncio.run(main())