Refine
This commit is contained in:
17
main.py
17
main.py
@@ -33,7 +33,7 @@ if not os.path.exists(inpDir):
|
||||
if not os.path.exists(tmpDir):
|
||||
os.mkdir(tmpDir)
|
||||
|
||||
lock_simulation = asyncio.Lock()
|
||||
lock_simulation = False
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@@ -150,18 +150,15 @@ async def fastapi_dump_inp(network: str, inp: str) -> bool:
|
||||
|
||||
# 必须用这个PlainTextResponse,不然每个key都有引号
|
||||
@app.get("/runproject/", response_class = PlainTextResponse)
|
||||
async def fastapi_run_project(network: str) -> str:
|
||||
def fastapi_run_project(network: str) -> str:
|
||||
|
||||
if lock_simulation.locked():
|
||||
if lock_simulation:
|
||||
raise HTTPException(status_code=409, detail="is in simulation")
|
||||
|
||||
await lock_simulation.acquire()
|
||||
|
||||
try:
|
||||
result = run_project(network)
|
||||
return result
|
||||
finally:
|
||||
lock_simulation.release() # Release the lock
|
||||
lock_simulation = True
|
||||
result = run_project(network)
|
||||
lock_simulation = False
|
||||
return result
|
||||
|
||||
# put in inp folder, name without extension
|
||||
@app.get("/runinp/")
|
||||
|
||||
Reference in New Issue
Block a user