Spaces:
Runtime error
Runtime error
Upload edgar_client.py
Browse files- edgar_client.py +43 -68
edgar_client.py
CHANGED
|
@@ -67,80 +67,55 @@ class EdgarDataClient:
|
|
| 67 |
if not self.edgar:
|
| 68 |
return
|
| 69 |
|
| 70 |
-
# Wrap get_submissions and get_company_facts with timeout
|
| 71 |
original_get_submissions = self.edgar.get_submissions
|
| 72 |
original_get_company_facts = self.edgar.get_company_facts
|
| 73 |
|
| 74 |
def get_submissions_with_timeout(cik):
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
exception[0] = e
|
| 97 |
-
|
| 98 |
-
thread = threading.Thread(target=wrapper, daemon=True)
|
| 99 |
-
thread.start()
|
| 100 |
-
thread.join(timeout=self.timeout)
|
| 101 |
-
|
| 102 |
-
if thread.is_alive():
|
| 103 |
-
raise TimeoutError("SEC API request timeout (30s)")
|
| 104 |
-
|
| 105 |
-
if exception[0]:
|
| 106 |
-
raise exception[0]
|
| 107 |
-
|
| 108 |
-
return result[0]
|
| 109 |
|
| 110 |
def get_company_facts_with_timeout(cik):
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
thread = threading.Thread(target=wrapper, daemon=True)
|
| 134 |
-
thread.start()
|
| 135 |
-
thread.join(timeout=self.timeout)
|
| 136 |
-
|
| 137 |
-
if thread.is_alive():
|
| 138 |
-
raise TimeoutError("SEC API request timeout (30s)")
|
| 139 |
-
|
| 140 |
-
if exception[0]:
|
| 141 |
-
raise exception[0]
|
| 142 |
-
|
| 143 |
-
return result[0]
|
| 144 |
|
| 145 |
self.edgar.get_submissions = get_submissions_with_timeout
|
| 146 |
self.edgar.get_company_facts = get_company_facts_with_timeout
|
|
|
|
| 67 |
if not self.edgar:
|
| 68 |
return
|
| 69 |
|
| 70 |
+
# Wrap get_submissions and get_company_facts with timeout (thread-based, Gradio compatible)
|
| 71 |
original_get_submissions = self.edgar.get_submissions
|
| 72 |
original_get_company_facts = self.edgar.get_company_facts
|
| 73 |
|
| 74 |
def get_submissions_with_timeout(cik):
|
| 75 |
+
"""Thread-based timeout wrapper for get_submissions (Gradio compatible)"""
|
| 76 |
+
result = [None]
|
| 77 |
+
exception = [None]
|
| 78 |
+
|
| 79 |
+
def wrapper():
|
| 80 |
+
try:
|
| 81 |
+
result[0] = original_get_submissions(cik)
|
| 82 |
+
except Exception as e:
|
| 83 |
+
exception[0] = e
|
| 84 |
+
|
| 85 |
+
thread = threading.Thread(target=wrapper, daemon=True)
|
| 86 |
+
thread.start()
|
| 87 |
+
thread.join(timeout=self.timeout)
|
| 88 |
+
|
| 89 |
+
if thread.is_alive():
|
| 90 |
+
raise TimeoutError(f"SEC API request timeout ({self.timeout}s)")
|
| 91 |
+
|
| 92 |
+
if exception[0]:
|
| 93 |
+
raise exception[0]
|
| 94 |
+
|
| 95 |
+
return result[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
def get_company_facts_with_timeout(cik):
|
| 98 |
+
"""Thread-based timeout wrapper for get_company_facts (Gradio compatible)"""
|
| 99 |
+
result = [None]
|
| 100 |
+
exception = [None]
|
| 101 |
+
|
| 102 |
+
def wrapper():
|
| 103 |
+
try:
|
| 104 |
+
result[0] = original_get_company_facts(cik)
|
| 105 |
+
except Exception as e:
|
| 106 |
+
exception[0] = e
|
| 107 |
+
|
| 108 |
+
thread = threading.Thread(target=wrapper, daemon=True)
|
| 109 |
+
thread.start()
|
| 110 |
+
thread.join(timeout=self.timeout)
|
| 111 |
+
|
| 112 |
+
if thread.is_alive():
|
| 113 |
+
raise TimeoutError(f"SEC API request timeout ({self.timeout}s)")
|
| 114 |
+
|
| 115 |
+
if exception[0]:
|
| 116 |
+
raise exception[0]
|
| 117 |
+
|
| 118 |
+
return result[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
self.edgar.get_submissions = get_submissions_with_timeout
|
| 121 |
self.edgar.get_company_facts = get_company_facts_with_timeout
|