diff --git a/main.py b/main.py index 25bdcb6..c78e1b2 100644 --- a/main.py +++ b/main.py @@ -12,6 +12,7 @@ from fastapi.responses import PlainTextResponse from fastapi.middleware.gzip import GZipMiddleware from tjnetwork import * import asyncio +import threading JUNCTION = 0 RESERVOIR = 1 @@ -145,7 +146,7 @@ async def fastapi_dump_inp(network: str, inp: str) -> bool: dump_inp(network, inp) return True -lock = asyncio.Lock() +lock = threading.Lock() # 必须用这个PlainTextResponse,不然每个key都有引号 @app.get("/runproject/", response_class = PlainTextResponse) @@ -154,7 +155,7 @@ async def fastapi_run_project(network: str) -> str: raise HTTPException(status_code=400, detail="is in simulation") else: try: - async with lock: + with lock: result = run_project(network) return result except asyncio.CancelledError: