openhands commited on
Commit
9da8453
·
1 Parent(s): 87e9f6b

Remove signal-based timeout (incompatible with HF Spaces)

Browse files

- signal.SIGALRM not available/working in HF Spaces environment
- Rely on subprocess timeouts which work correctly
- Add try-except blocks around data fetch/copy for better error handling
- Simplify setup_mock_data() implementation

Files changed (1) hide show
  1. setup_data.py +14 -36
setup_data.py CHANGED
@@ -5,18 +5,11 @@ This runs before the app starts to ensure data is available.
5
  import os
6
  import shutil
7
  import subprocess
8
- import signal
9
  from pathlib import Path
10
  from config import DATA_DIR, EXTRACTED_DATA_DIR, CONFIG_NAME
11
 
12
  GITHUB_REPO = "https://github.com/OpenHands/openhands-index-results.git"
13
 
14
- class TimeoutError(Exception):
15
- pass
16
-
17
- def timeout_handler(signum, frame):
18
- raise TimeoutError("Operation timed out")
19
-
20
  def fetch_data_from_github():
21
  """
22
  Fetch data from the openhands-index-results GitHub repository.
@@ -126,9 +119,9 @@ def copy_mock_data():
126
  print(f"Target directory: {target_dir.absolute()}")
127
  return True
128
 
129
- def _setup_mock_data_impl():
130
  """
131
- Internal implementation of setup data for the leaderboard.
132
  First tries to fetch from GitHub, falls back to mock data if unavailable.
133
  """
134
  print("=" * 60)
@@ -146,40 +139,25 @@ def _setup_mock_data_impl():
146
 
147
  # Try to fetch from GitHub first
148
  print("\n--- Attempting to fetch from GitHub ---")
149
- if fetch_data_from_github():
150
- print("✓ Successfully using data from GitHub repository")
151
- return
 
 
 
152
 
153
  # Fall back to mock data
154
  print("\n--- GitHub data not available, falling back to mock data ---")
155
- if copy_mock_data():
156
- print("✓ Successfully using mock data")
157
- return
 
 
 
158
 
159
  print("\n" + "!" * 60)
160
  print("ERROR: No data available! Neither GitHub nor mock data could be loaded.")
161
  print("!" * 60)
162
 
163
- def setup_mock_data():
164
- """
165
- Wrapper for setup_mock_data with timeout protection.
166
- """
167
- try:
168
- # Set a timeout of 60 seconds for the entire setup
169
- signal.signal(signal.SIGALRM, timeout_handler)
170
- signal.alarm(60)
171
-
172
- _setup_mock_data_impl()
173
-
174
- # Cancel the alarm
175
- signal.alarm(0)
176
- except TimeoutError:
177
- print("!!! TIMEOUT: Data setup took too long (>60s), skipping...")
178
- signal.alarm(0) # Cancel the alarm
179
- except Exception as e:
180
- print(f"!!! ERROR during setup: {e}")
181
- signal.alarm(0) # Cancel the alarm
182
- raise
183
-
184
  if __name__ == "__main__":
185
  setup_mock_data()
 
5
  import os
6
  import shutil
7
  import subprocess
 
8
  from pathlib import Path
9
  from config import DATA_DIR, EXTRACTED_DATA_DIR, CONFIG_NAME
10
 
11
  GITHUB_REPO = "https://github.com/OpenHands/openhands-index-results.git"
12
 
 
 
 
 
 
 
13
  def fetch_data_from_github():
14
  """
15
  Fetch data from the openhands-index-results GitHub repository.
 
119
  print(f"Target directory: {target_dir.absolute()}")
120
  return True
121
 
122
+ def setup_mock_data():
123
  """
124
+ Setup data for the leaderboard.
125
  First tries to fetch from GitHub, falls back to mock data if unavailable.
126
  """
127
  print("=" * 60)
 
139
 
140
  # Try to fetch from GitHub first
141
  print("\n--- Attempting to fetch from GitHub ---")
142
+ try:
143
+ if fetch_data_from_github():
144
+ print("✓ Successfully using data from GitHub repository")
145
+ return
146
+ except Exception as e:
147
+ print(f"GitHub fetch failed with error: {e}")
148
 
149
  # Fall back to mock data
150
  print("\n--- GitHub data not available, falling back to mock data ---")
151
+ try:
152
+ if copy_mock_data():
153
+ print("✓ Successfully using mock data")
154
+ return
155
+ except Exception as e:
156
+ print(f"Mock data copy failed with error: {e}")
157
 
158
  print("\n" + "!" * 60)
159
  print("ERROR: No data available! Neither GitHub nor mock data could be loaded.")
160
  print("!" * 60)
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  if __name__ == "__main__":
163
  setup_mock_data()