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