Spaces:
Sleeping
Sleeping
Commit
·
f1abaf7
1
Parent(s):
c8da929
fix aync requests
Browse files
main.py
CHANGED
@@ -818,18 +818,21 @@ class HealthcareChatbot:
|
|
818 |
# loop.close()
|
819 |
# except:
|
820 |
# print(traceback.format_exc())
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
|
|
|
|
|
|
833 |
|
834 |
print("🔗 API response received:", api_response)
|
835 |
|
|
|
818 |
# loop.close()
|
819 |
# except:
|
820 |
# print(traceback.format_exc())
|
821 |
+
try:
|
822 |
+
def run_async():
|
823 |
+
new_loop = asyncio.new_event_loop()
|
824 |
+
asyncio.set_event_loop(new_loop)
|
825 |
+
try:
|
826 |
+
return new_loop.run_until_complete(self.backend_call(router_data))
|
827 |
+
finally:
|
828 |
+
new_loop.close()
|
829 |
+
|
830 |
+
import concurrent.futures
|
831 |
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
832 |
+
future = executor.submit(run_async)
|
833 |
+
api_response = future.result(timeout=30) # 30 second timeout
|
834 |
+
except:
|
835 |
+
print(traceback.format_exc())
|
836 |
|
837 |
print("🔗 API response received:", api_response)
|
838 |
|