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