Refine
This commit is contained in:
18
main.py
18
main.py
@@ -35,6 +35,8 @@ if not os.path.exists(tmpDir):
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
lock_simulation = asyncio.Lock()
|
||||||
|
|
||||||
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
@@ -146,20 +148,18 @@ async def fastapi_dump_inp(network: str, inp: str) -> bool:
|
|||||||
dump_inp(network, inp)
|
dump_inp(network, inp)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
app.state.lock_simulation = False
|
|
||||||
|
|
||||||
# 必须用这个PlainTextResponse,不然每个key都有引号
|
# 必须用这个PlainTextResponse,不然每个key都有引号
|
||||||
@app.get("/runproject/", response_class = PlainTextResponse)
|
@app.get("/runproject/", response_class = PlainTextResponse)
|
||||||
async def fastapi_run_project(network: str) -> str:
|
async def fastapi_run_project(network: str) -> str:
|
||||||
print(app.state.lock_simulation)
|
global lock_simulation
|
||||||
if app.state.lock_simulation:
|
|
||||||
|
if lock_simulation.locked:
|
||||||
raise HTTPException(status_code=409, detail="is in simulation")
|
raise HTTPException(status_code=409, detail="is in simulation")
|
||||||
|
|
||||||
app.state.lock_simulation = True
|
async with lock_simulation:
|
||||||
print('lock simulation')
|
print('lock simulation')
|
||||||
result = run_project(network)
|
result = run_project(network)
|
||||||
app.state.lock_simulation = False
|
return result
|
||||||
return result
|
|
||||||
|
|
||||||
# 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