Spaces:
Sleeping
Sleeping
Download server/templates/level_10/middleware.py from anonajay/lint_coding_agent: direct link, hf CLI and curl.
- Browser
- Download file 762 Bytes
-
https://huggingface.co/spaces/anonajay/lint_coding_agent/resolve/main/server/templates/level_10/middleware.py
- Command line
-
hf download hf://spaces/anonajay/lint_coding_agent/server/templates/level_10/middleware.py
-
curl -L -o middleware.py https://huggingface.co/spaces/anonajay/lint_coding_agent/resolve/main/server/templates/level_10/middleware.py
762 Bytes
| import asyncio | |
| # BROKEN: This global variable is shared across all async tasks. | |
| # Task A will set this, then 'await'. Task B will then overwrite it. | |
| request_store = {"id": None} | |
| async def process_request(req_id): | |
| request_store["id"] = req_id | |
| # Simulate a database call or API hit | |
| await asyncio.sleep(1) | |
| # By the time we get here, another request might have | |
| # changed request_store["id"] | |
| return f"Finished request: {request_store['id']}" | |
| async def main(): | |
| # Simulate two concurrent requests | |
| results = await asyncio.gather( | |
| process_request("REQ-100"), | |
| process_request("REQ-200") | |
| ) | |
| print(results) # Likely to show ['Finished request: REQ-200', 'Finished request: REQ-200'] |