冲突解决

This commit is contained in:
wudong 2022-11-24 10:48:28 +08:00
commit 54f4b653be
5 changed files with 32 additions and 28 deletions

View File

@ -8,7 +8,8 @@
""" """
import multiprocessing import multiprocessing
global active_connections
global active_connections_dist
def _init(): # 初始化 def _init(): # 初始化
# 中断标志 # 中断标志
@ -16,14 +17,18 @@ def _init(): # 初始化
_global_dict = {} _global_dict = {}
# ws列表存储 # ws列表存储
global active_connections
active_connections = multiprocessing.Manager().list() active_connections = multiprocessing.Manager().list()
# ws字典存储 # ws字典存储
global active_connections_dist
active_connections_dist = multiprocessing.Manager().dict() active_connections_dist = multiprocessing.Manager().dict()
def get_active_connections():
return active_connections
def get_active_connections_dist():
return active_connections_dist
def set_value(key, value): def set_value(key, value):
# 定义一个全局变量 # 定义一个全局变量
_global_dict[key] = value _global_dict[key] = value

View File

@ -10,11 +10,7 @@ from flask_sockets import Sockets
import sys import sys
<<<<<<< HEAD
sys.path.append("/mnt/sdc/algorithm/R-ODY") sys.path.append("/mnt/sdc/algorithm/R-ODY")
=======
sys.path.append("/mnt/sdc/algorithm/AICheck-MaskRCNN")
>>>>>>> 168c803f56a54a8da33a41e91459154b9abe9dbd
# sys.path.append('E:/alg_demo-master/alg_demo/app/yolov5') # sys.path.append('E:/alg_demo-master/alg_demo/app/yolov5')
from app.core.common_utils import logger from app.core.common_utils import logger
from app.core.err_handler import page_not_found, method_not_allowed, exception_500, exception_400 from app.core.err_handler import page_not_found, method_not_allowed, exception_500, exception_400

View File

@ -1,8 +1,6 @@
""" """
@Time 2022/10/12 17:55 @Time 2022/10/12 17:55
@Auth @Auth
@File websocket_tool.py
@IDE PyCharm
@MottoABC(Always Be Coding) @MottoABC(Always Be Coding)
@Desc @Desc
@ -10,32 +8,35 @@
import json import json
from typing import Union, List, Dict from typing import Union, List, Dict
from core.common_utils import logger from app.core.common_utils import logger
from utils.JSONEncodeTools import MyEncoder from app.utils.JSONEncodeTools import MyEncoder
from configs.global_var import *
class WebsocketUtil: class WebsocketUtil:
def __init__(self):
self.active_connections: List = []
self.active_connections_dist: Dict = {}
def connect(self, ws, id: str): def connect(self, ws, id: str):
# 等待连接 # 等待连接
msg = ws.receive() msg = ws.receive()
# 存储ws连接对象 # 存储ws连接对象
self.active_connections.append(ws) global active_connections
if id in self.active_connections_dist: # active_connections = get_active_connections()
self.active_connections_dist[id].append(ws) active_connections.append(ws)
global active_connections_dist
# active_connections_dist = get_active_connections_dist()
if id in active_connections_dist:
active_connections_dist[id].append(ws)
else: else:
ws_list = [ws, ] ws_list = [ws, ]
self.active_connections_dist[id] = ws_list active_connections_dist[id] = ws_list
def disconnect(self, ws, id): def disconnect(self, ws, id):
# ws关闭时 移除ws对象 # ws关闭时 移除ws对象
if ws.closed: if ws.closed:
if ws in self.active_connections_dist.values(): if ws in active_connections_dist.values():
self.active_connections.remove(ws) global active_connections
self.active_connections_dist[id].pop(ws) active_connections.remove(ws)
global active_connections_dist
active_connections_dist[id].pop(ws)
@staticmethod @staticmethod
async def send_personal_message(message: str, ws): async def send_personal_message(message: str, ws):
@ -44,12 +45,14 @@ class WebsocketUtil:
def broadcast(self, message: str): def broadcast(self, message: str):
# 广播消息 # 广播消息
for connection in self.active_connections: global active_connections
for connection in active_connections:
connection.send(message) connection.send(message)
def send_message_proj_json(self, message: Union[str, int, List, Dict], id: str): def send_message_proj_json(self, message: Union[str, int, List, Dict], id: str):
# 广播该项目的消息 # 广播该项目的消息
for connection in self.active_connections_dist[id]: global active_connections_dist
for connection in active_connections_dist[id]:
try: try:
connection.send(json.dumps(message, cls=MyEncoder, indent=4), ) connection.send(json.dumps(message, cls=MyEncoder, indent=4), )
except Exception as e: except Exception as e:

View File

@ -1,9 +1,9 @@
path: null path: null
train: /mnt/sdc/IntelligentizeAI/IntelligentizeAI/data_set/190857268466688000/trained/images/train/ train: /mnt/sdc/aicheck/IntelligentizeAI/data_set/193120735164768256/trained/images/train/
val: /mnt/sdc/IntelligentizeAI/IntelligentizeAI/data_set/190857268466688000/trained/images/val/ val: /mnt/sdc/aicheck/IntelligentizeAI/data_set/193120735164768256/trained/images/val/
test: null test: null
names: names:
0: hole 0: hole
1: '456' 1: '456'
2: zui 2: dog
3: mianbang 3: cat

BIN
nohup.out

Binary file not shown.