This commit is contained in:
DingZQ
2023-10-21 09:01:58 +08:00
parent a8dd94bf20
commit ff7b1c921d

13
main.py
View File

@@ -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:
lock_simulation = True
result = run_project(network)
lock_simulation = False
return result
finally:
lock_simulation.release() # Release the lock
# put in inp folder, name without extension
@app.get("/runinp/")