Spaces:
Paused
Paused
Commit
·
72af80c
1
Parent(s):
f4fae5e
feat: fix bug
Browse files- web_server.py +14 -8
web_server.py
CHANGED
|
@@ -127,11 +127,13 @@ def update_submission_status(team_id: str, submission_id: str, status: int):
|
|
| 127 |
|
| 128 |
|
| 129 |
def delete_client_space(client_space_id: str):
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
class FifoDict:
|
|
@@ -313,6 +315,7 @@ class EnvHandlerManager:
|
|
| 313 |
"""
|
| 314 |
with self._lock:
|
| 315 |
env = self._env_handlers.pop(env_id, None)
|
|
|
|
| 316 |
if env is not None:
|
| 317 |
env.close()
|
| 318 |
torch.cuda.empty_cache()
|
|
@@ -335,7 +338,10 @@ def _get_env_handler(
|
|
| 335 |
token_info = get_token_info(token)
|
| 336 |
except Exception:
|
| 337 |
raise HTTPException(status_code=401)
|
| 338 |
-
|
|
|
|
|
|
|
|
|
|
| 339 |
|
| 340 |
|
| 341 |
def _load_numpy_ndarray_json_str(json_str: str) -> np.ndarray:
|
|
@@ -385,7 +391,7 @@ def execute_action_endpoint(
|
|
| 385 |
return Response(content=cache_result, media_type="application/octet-stream")
|
| 386 |
|
| 387 |
if env_handler.has_done:
|
| 388 |
-
result = pickle.dumps({"done": True, "state":
|
| 389 |
_result_dict.push(transaction_id, result)
|
| 390 |
return Response(content=result, media_type="application/octet-stream")
|
| 391 |
|
|
@@ -402,7 +408,7 @@ def execute_action_endpoint(
|
|
| 402 |
repo_type="dataset",
|
| 403 |
path_in_repo=f"eval_results/{token_info['submission_id']}",
|
| 404 |
)
|
| 405 |
-
result = pickle.dumps({"done": done, "state":
|
| 406 |
_result_dict.push(transaction_id, result)
|
| 407 |
return Response(content=result, media_type="application/octet-stream")
|
| 408 |
|
|
|
|
| 127 |
|
| 128 |
|
| 129 |
def delete_client_space(client_space_id: str):
|
| 130 |
+
try:
|
| 131 |
+
hf_api.delete_repo(
|
| 132 |
+
repo_id=client_space_id,
|
| 133 |
+
repo_type="space"
|
| 134 |
+
)
|
| 135 |
+
except:
|
| 136 |
+
print(f"Failed to delete space {client_space_id}. It may not exist or already deleted.")
|
| 137 |
|
| 138 |
|
| 139 |
class FifoDict:
|
|
|
|
| 315 |
"""
|
| 316 |
with self._lock:
|
| 317 |
env = self._env_handlers.pop(env_id, None)
|
| 318 |
+
self._env_handlers[env_id] = None
|
| 319 |
if env is not None:
|
| 320 |
env.close()
|
| 321 |
torch.cuda.empty_cache()
|
|
|
|
| 338 |
token_info = get_token_info(token)
|
| 339 |
except Exception:
|
| 340 |
raise HTTPException(status_code=401)
|
| 341 |
+
env_handler = env_manager.get_env_handler(token_info["submission_id"])
|
| 342 |
+
if env_handler is None:
|
| 343 |
+
raise HTTPException(status_code=404, detail="Environment handler already closed.")
|
| 344 |
+
return env_handler
|
| 345 |
|
| 346 |
|
| 347 |
def _load_numpy_ndarray_json_str(json_str: str) -> np.ndarray:
|
|
|
|
| 391 |
return Response(content=cache_result, media_type="application/octet-stream")
|
| 392 |
|
| 393 |
if env_handler.has_done:
|
| 394 |
+
result = pickle.dumps({"done": True, "state": env_handler.get_current_state()})
|
| 395 |
_result_dict.push(transaction_id, result)
|
| 396 |
return Response(content=result, media_type="application/octet-stream")
|
| 397 |
|
|
|
|
| 408 |
repo_type="dataset",
|
| 409 |
path_in_repo=f"eval_results/{token_info['submission_id']}",
|
| 410 |
)
|
| 411 |
+
result = pickle.dumps({"done": done, "state": env_handler.get_current_state()})
|
| 412 |
_result_dict.push(transaction_id, result)
|
| 413 |
return Response(content=result, media_type="application/octet-stream")
|
| 414 |
|