Refine
This commit is contained in:
5
main.py
5
main.py
@@ -12,6 +12,7 @@ from fastapi.responses import PlainTextResponse
|
|||||||
from fastapi.middleware.gzip import GZipMiddleware
|
from fastapi.middleware.gzip import GZipMiddleware
|
||||||
from tjnetwork import *
|
from tjnetwork import *
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import threading
|
||||||
|
|
||||||
JUNCTION = 0
|
JUNCTION = 0
|
||||||
RESERVOIR = 1
|
RESERVOIR = 1
|
||||||
@@ -145,7 +146,7 @@ async def fastapi_dump_inp(network: str, inp: str) -> bool:
|
|||||||
dump_inp(network, inp)
|
dump_inp(network, inp)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
lock = asyncio.Lock()
|
lock = threading.Lock()
|
||||||
|
|
||||||
# 必须用这个PlainTextResponse,不然每个key都有引号
|
# 必须用这个PlainTextResponse,不然每个key都有引号
|
||||||
@app.get("/runproject/", response_class = PlainTextResponse)
|
@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")
|
raise HTTPException(status_code=400, detail="is in simulation")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
async with lock:
|
with lock:
|
||||||
result = run_project(network)
|
result = run_project(network)
|
||||||
return result
|
return result
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
|
|||||||
Reference in New Issue
Block a user