Refine
This commit is contained in:
4
main.py
4
main.py
@@ -150,12 +150,12 @@ app.state.lock = asyncio.Lock() # Create an async lock object
|
|||||||
|
|
||||||
# 必须用这个PlainTextResponse,不然每个key都有引号
|
# 必须用这个PlainTextResponse,不然每个key都有引号
|
||||||
@app.get("/runproject/", response_class = PlainTextResponse)
|
@app.get("/runproject/", response_class = PlainTextResponse)
|
||||||
async def fastapi_run_project(network: str) -> str:
|
def fastapi_run_project(network: str) -> str:
|
||||||
if app.state.lock.locked():
|
if app.state.lock.locked():
|
||||||
raise HTTPException(status_code=400, detail="is in simulation")
|
raise HTTPException(status_code=400, detail="is in simulation")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
await app.state.lock.acquire() # Acquire the lock
|
app.state.lock.acquire() # Acquire the lock
|
||||||
result = run_project(network)
|
result = run_project(network)
|
||||||
return result
|
return result
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
|
|||||||
Reference in New Issue
Block a user