Refine
This commit is contained in:
7
main.py
7
main.py
@@ -13,6 +13,7 @@ from fastapi.middleware.gzip import GZipMiddleware
|
|||||||
from tjnetwork import *
|
from tjnetwork import *
|
||||||
import asyncio
|
import asyncio
|
||||||
import threading
|
import threading
|
||||||
|
from multiprocessing import Value
|
||||||
|
|
||||||
JUNCTION = 0
|
JUNCTION = 0
|
||||||
RESERVOIR = 1
|
RESERVOIR = 1
|
||||||
@@ -35,7 +36,8 @@ if not os.path.exists(tmpDir):
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
lock_simulation = asyncio.Lock()
|
# 定义一个共享变量
|
||||||
|
lock_simulaiton = Value('i', 0)
|
||||||
|
|
||||||
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
||||||
|
|
||||||
@@ -156,8 +158,9 @@ async def fastapi_run_project(network: str) -> str:
|
|||||||
if lock_simulation.locked:
|
if lock_simulation.locked:
|
||||||
raise HTTPException(status_code=409, detail="is in simulation")
|
raise HTTPException(status_code=409, detail="is in simulation")
|
||||||
|
|
||||||
async with lock_simulation:
|
with lock_simulation.get_lock():
|
||||||
print('lock simulation')
|
print('lock simulation')
|
||||||
|
lock_simulation.value = 1
|
||||||
result = run_project(network)
|
result = run_project(network)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user