From 0151fb3424ad6c5e31a33a81045e6847aaa7efe6 Mon Sep 17 00:00:00 2001 From: DingZQ Date: Fri, 27 Oct 2023 21:08:24 +0800 Subject: [PATCH] Refine --- main.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 8099b1a..d1d2261 100644 --- a/main.py +++ b/main.py @@ -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