更新事件循环策略
This commit is contained in:
3
main.py
3
main.py
@@ -3487,7 +3487,6 @@ async def fastapi_run_simulation_manually_by_date(
|
||||
thread.start()
|
||||
thread.join() # 等待线程完成
|
||||
|
||||
|
||||
return {"status": "success"}
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": str(e)}
|
||||
@@ -4232,7 +4231,7 @@ async def get_dict(item: Item):
|
||||
if __name__ == "__main__":
|
||||
# uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||
# url='http://127.0.0.1:8000/valve_close_analysis?network=beibeizone&start_time=2024-04-01T08:00:00Z&valve_IDs=GSD2307192058577780A3287D78&valve_IDs=GSD2307192058572E953B707226(S2)&duration=1800'
|
||||
url='http://127.0.0.1:8000/burst_analysis?network=beibeizone&start_time=2024-04-01T08:00:00Z&burst_ID=ZBBGXSZW000001&duration=1800'
|
||||
url = "http://127.0.0.1:8000/burst_analysis?network=beibeizone&start_time=2024-04-01T08:00:00Z&burst_ID=ZBBGXSZW000001&duration=1800"
|
||||
# url = "http://192.168.1.36:8000/queryallschemeallrecords/?schemename=Fangan0817114448&querydate=2025-08-13&schemetype=burst_Analysis"
|
||||
# response = Request.get(url)
|
||||
|
||||
|
||||
@@ -1,6 +1,27 @@
|
||||
import asyncio
|
||||
import sys
|
||||
import uvicorn
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||
uvicorn.run("main:app", host="0.0.0.0", port=8000)
|
||||
# Windows 设置事件循环策略
|
||||
if sys.platform == "win32":
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||
|
||||
# 创建配置对象
|
||||
config = uvicorn.Config(
|
||||
"main:app",
|
||||
host="0.0.0.0",
|
||||
port=8000,
|
||||
loop="asyncio", # 强制使用 asyncio 事件循环
|
||||
# workers=4, # 如果需要多进程,可以取消注释
|
||||
)
|
||||
server = uvicorn.Server(config)
|
||||
|
||||
# 创建并设置事件循环
|
||||
if sys.platform == "win32":
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
|
||||
# 运行服务器
|
||||
asyncio.run(server.serve())
|
||||
|
||||
Reference in New Issue
Block a user