Refine
This commit is contained in:
13
main.py
13
main.py
@@ -33,8 +33,6 @@ 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 = False
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
||||||
@@ -148,16 +146,17 @@ 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)
|
||||||
def fastapi_run_project(network: str) -> str:
|
async def fastapi_run_project(network: str) -> str:
|
||||||
global lock_simulation
|
if app.state.lock_simulation:
|
||||||
if lock_simulation:
|
|
||||||
raise HTTPException(status_code=409, detail="is in simulation")
|
raise HTTPException(status_code=409, detail="is in simulation")
|
||||||
|
|
||||||
lock_simulation = True
|
app.state.lock_simulation = True
|
||||||
result = run_project(network)
|
result = run_project(network)
|
||||||
lock_simulation = False
|
app.state.lock_simulation = False
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# put in inp folder, name without extension
|
# put in inp folder, name without extension
|
||||||
|
|||||||
Reference in New Issue
Block a user