This commit is contained in:
DingZQ
2023-10-27 21:08:24 +08:00
parent 855cf6758a
commit 0151fb3424

17
main.py
View File

@@ -153,18 +153,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:
global lock_simulation
print('lock simulation')
print(lock_simulation.value)
if lock_simulation.value == 1:
filename = 'lock.simulation'
if os.path.exists(filename):
raise HTTPException(status_code=409, detail="is in simulation")
with lock_simulation.get_lock():
lock_simulation.value = 1
else:
f = open(filename, "w")
f.write("locksimulaiton")
f.close()
result = run_project(network)
lock_simulation.value = 0
os.remove(filename)
return result
# put in inp folder, name without extension