|
@@ -1,4 +1,6 @@
|
|
# -*- coding:utf-8 -*-
|
|
# -*- coding:utf-8 -*-
|
|
|
|
+import argparse
|
|
|
|
+import copy
|
|
import hashlib
|
|
import hashlib
|
|
import inspect
|
|
import inspect
|
|
import json
|
|
import json
|
|
@@ -24,6 +26,7 @@ from format_convert import _global
|
|
from functools import wraps
|
|
from functools import wraps
|
|
import psutil
|
|
import psutil
|
|
import time
|
|
import time
|
|
|
|
+import numpy as np
|
|
from format_convert.judge_platform import get_platform
|
|
from format_convert.judge_platform import get_platform
|
|
if get_platform() == "Linux":
|
|
if get_platform() == "Linux":
|
|
import resource
|
|
import resource
|
|
@@ -58,7 +61,7 @@ def add_div(text):
|
|
return text
|
|
return text
|
|
|
|
|
|
text = "<div>" + text + "\n"
|
|
text = "<div>" + text + "\n"
|
|
- text = re.sub("\n", "</div>\n<div>", text)
|
|
|
|
|
|
+ text = re.sub("\n", "</div><div>", text)
|
|
# text += "</div>"
|
|
# text += "</div>"
|
|
if text[-5:] == "<div>":
|
|
if text[-5:] == "<div>":
|
|
# print("add_div has cut", text[-30:])
|
|
# print("add_div has cut", text[-30:])
|
|
@@ -522,7 +525,6 @@ class LineTable:
|
|
self.list_line = list_line
|
|
self.list_line = list_line
|
|
self.list_crosspoints = self.recognize_crosspoints(list_line)
|
|
self.list_crosspoints = self.recognize_crosspoints(list_line)
|
|
|
|
|
|
-
|
|
|
|
# 聚类
|
|
# 聚类
|
|
cluster_crosspoints = []
|
|
cluster_crosspoints = []
|
|
for _point in self.list_crosspoints:
|
|
for _point in self.list_crosspoints:
|
|
@@ -1076,8 +1078,10 @@ class LineTable:
|
|
# for _textbox in list_textbox:
|
|
# for _textbox in list_textbox:
|
|
# print(_textbox.get_text())
|
|
# print(_textbox.get_text())
|
|
# print("textbox:======>>>>>>>>>>>>>")
|
|
# print("textbox:======>>>>>>>>>>>>>")
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ # for c in clusters_rects:
|
|
|
|
+ # print("+"*30)
|
|
|
|
+ # for cc in c:
|
|
|
|
+ # print("rect", cc.)
|
|
# cul spans
|
|
# cul spans
|
|
for _line in clusters_rects:
|
|
for _line in clusters_rects:
|
|
for _rect in _line:
|
|
for _rect in _line:
|
|
@@ -1142,19 +1146,69 @@ class LineTable:
|
|
list_textbox.sort(key=lambda x:x.bbox[0])
|
|
list_textbox.sort(key=lambda x:x.bbox[0])
|
|
list_textbox.sort(key=lambda x:x.bbox[3],reverse=sourceP_LB)
|
|
list_textbox.sort(key=lambda x:x.bbox[3],reverse=sourceP_LB)
|
|
# print("list_textbox", list_textbox)
|
|
# print("list_textbox", list_textbox)
|
|
- for textbox in list_textbox:
|
|
|
|
- (x0,y0,x1,y1) = textbox.bbox
|
|
|
|
- _text = textbox.get_text()
|
|
|
|
- _find = False
|
|
|
|
- for table_line in _table:
|
|
|
|
- for _cell in table_line:
|
|
|
|
|
|
+ # for textbox in list_textbox:
|
|
|
|
+ # (x0,y0,x1,y1) = textbox.bbox
|
|
|
|
+ # _text = textbox.get_text()
|
|
|
|
+ # _find = False
|
|
|
|
+ # for table_line in _table:
|
|
|
|
+ # for _cell in table_line:
|
|
|
|
+ # if self.inbox(textbox.bbox, _cell["bbox"], textbox.get_text()):
|
|
|
|
+ # _cell["text"] += _text
|
|
|
|
+ # in_objs.add(textbox)
|
|
|
|
+ # _find = True
|
|
|
|
+ # break
|
|
|
|
+ # if _find:
|
|
|
|
+ # break
|
|
|
|
+ has_matched_box_list = []
|
|
|
|
+ for table_line in _table:
|
|
|
|
+ for _cell in table_line:
|
|
|
|
+ inbox_textbox_list = []
|
|
|
|
+ for textbox in list_textbox:
|
|
|
|
+ if textbox in in_objs:
|
|
|
|
+ continue
|
|
if self.inbox(textbox.bbox, _cell["bbox"], textbox.get_text()):
|
|
if self.inbox(textbox.bbox, _cell["bbox"], textbox.get_text()):
|
|
- _cell["text"] += _text
|
|
|
|
|
|
+ inbox_textbox_list.append(textbox)
|
|
in_objs.add(textbox)
|
|
in_objs.add(textbox)
|
|
- _find = True
|
|
|
|
- break
|
|
|
|
- if _find:
|
|
|
|
- break
|
|
|
|
|
|
+
|
|
|
|
+ # 分行,根据y重合
|
|
|
|
+ all_match_box_list = []
|
|
|
|
+ for i in range(len(inbox_textbox_list)):
|
|
|
|
+ match_box_list = []
|
|
|
|
+ box1 = inbox_textbox_list[i]
|
|
|
|
+ if box1 in has_matched_box_list:
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ min_y1 = box1.bbox[1] + 1/3 * abs(box1.bbox[3]-box1.bbox[1])
|
|
|
|
+ max_y1 = box1.bbox[3] - 1/3 * abs(box1.bbox[3]-box1.bbox[1])
|
|
|
|
+ match_box_list.append([box1.get_text(), box1.bbox[0], box1.bbox[1], box1.bbox[2], box1.bbox[3]])
|
|
|
|
+ has_matched_box_list.append(box1)
|
|
|
|
+ for j in range(i+1, len(inbox_textbox_list)):
|
|
|
|
+ box2 = inbox_textbox_list[j]
|
|
|
|
+ if box2 in has_matched_box_list:
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ # print(min_y1, box2.bbox[1], box2.bbox[3], max_y1)
|
|
|
|
+ # print(min_y2, box1.bbox[3], max_y2)
|
|
|
|
+ if min_y1 <= box2.bbox[1] <= max_y1 or \
|
|
|
|
+ min_y1 <= box2.bbox[3] <= max_y1 or \
|
|
|
|
+ box2.bbox[1] <= min_y1 <= max_y1 <= box2.bbox[3]:
|
|
|
|
+ match_box_list.append([box2.get_text(), box2.bbox[0], box2.bbox[1], box2.bbox[2], box2.bbox[3]])
|
|
|
|
+ has_matched_box_list.append(box2)
|
|
|
|
+ match_box_list.sort(key=lambda x: x[1])
|
|
|
|
+ all_match_box_list.append(match_box_list)
|
|
|
|
+
|
|
|
|
+ # print("match_box_list", all_match_box_list)
|
|
|
|
+ for box_list in all_match_box_list:
|
|
|
|
+ for box in box_list:
|
|
|
|
+ _cell["text"] += box[0]
|
|
|
|
+
|
|
|
|
+ # print("------------")
|
|
|
|
+ # for _line in _table:
|
|
|
|
+ # for _cell in _line:
|
|
|
|
+ # print(_cell["text"])
|
|
|
|
+ # print("\n")
|
|
|
|
+ # print("------------")
|
|
|
|
+
|
|
if fixspan:
|
|
if fixspan:
|
|
for _line in _table:
|
|
for _line in _table:
|
|
for c_i in range(len(_line)):
|
|
for c_i in range(len(_line)):
|
|
@@ -1181,17 +1235,6 @@ class LineTable:
|
|
# print(len(_table),l_i+i)
|
|
# print(len(_table),l_i+i)
|
|
_table[l_i+i].insert(c_i,n_cell)
|
|
_table[l_i+i].insert(c_i,n_cell)
|
|
|
|
|
|
-
|
|
|
|
- # print("=======")
|
|
|
|
- # for _line in _table:
|
|
|
|
- # for _cell in _line:
|
|
|
|
- # _text = _cell["text"][:2]+"_"+str(_cell["columnspan"])+"_"+str(_cell["rowspan"])
|
|
|
|
- # if _text=="":
|
|
|
|
- # _text = "=="
|
|
|
|
- # print(_text,end="\t")
|
|
|
|
- # print("\n")
|
|
|
|
- # print("===========")
|
|
|
|
-
|
|
|
|
if fixRect:
|
|
if fixRect:
|
|
for _line in _table:
|
|
for _line in _table:
|
|
extend_line = []
|
|
extend_line = []
|
|
@@ -1230,23 +1273,22 @@ class LineTable:
|
|
"columnspan": self.getspan(list_x, _bbox[0], _bbox[2], margin),
|
|
"columnspan": self.getspan(list_x, _bbox[0], _bbox[2], margin),
|
|
"text": ""}
|
|
"text": ""}
|
|
extend_line.append({"index":c_i+1,"cell":_cell})
|
|
extend_line.append({"index":c_i+1,"cell":_cell})
|
|
- extend_line.sort(key=lambda x:x["index"],reverse=True)
|
|
|
|
|
|
+ extend_line.sort(key=lambda x: x["index"],reverse=True)
|
|
|
|
|
|
for _tmp in extend_line:
|
|
for _tmp in extend_line:
|
|
_line.insert(_tmp["index"],_tmp["cell"])
|
|
_line.insert(_tmp["index"],_tmp["cell"])
|
|
|
|
|
|
-
|
|
|
|
- list_textbox.sort(key=lambda x:x.bbox[0])
|
|
|
|
- list_textbox.sort(key=lambda x:x.bbox[3],reverse=sourceP_LB)
|
|
|
|
|
|
+ list_textbox.sort(key=lambda x: x.bbox[0])
|
|
|
|
+ list_textbox.sort(key=lambda x: x.bbox[3], reverse=sourceP_LB)
|
|
for textbox in list_textbox:
|
|
for textbox in list_textbox:
|
|
if textbox in in_objs:
|
|
if textbox in in_objs:
|
|
continue
|
|
continue
|
|
- (x0,y0,x1,y1) = textbox.bbox
|
|
|
|
|
|
+ x0, y0, x1, y1 = textbox.bbox
|
|
_text = textbox.get_text()
|
|
_text = textbox.get_text()
|
|
_find = False
|
|
_find = False
|
|
for table_line in _table:
|
|
for table_line in _table:
|
|
for _cell in table_line:
|
|
for _cell in table_line:
|
|
- if self.inbox(textbox.bbox,_cell["bbox"], textbox.get_text()):
|
|
|
|
|
|
+ if self.inbox(textbox.bbox, _cell["bbox"], textbox.get_text()):
|
|
_cell["text"] += _text
|
|
_cell["text"] += _text
|
|
in_objs.add(textbox)
|
|
in_objs.add(textbox)
|
|
_find = True
|
|
_find = True
|
|
@@ -1254,26 +1296,18 @@ class LineTable:
|
|
if _find:
|
|
if _find:
|
|
break
|
|
break
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ table_bbox = (_table[0][0].get("bbox")[0],
|
|
|
|
+ _table[0][0].get("bbox")[1],
|
|
|
|
+ _table[-1][-1].get("bbox")[2],
|
|
|
|
+ _table[-1][-1].get("bbox")[3])
|
|
|
|
|
|
# print("=======")
|
|
# print("=======")
|
|
# for _line in _table:
|
|
# for _line in _table:
|
|
# for _cell in _line:
|
|
# for _cell in _line:
|
|
- # _text = _cell["text"][:2]
|
|
|
|
- # if _text=="":
|
|
|
|
- # _text = "=="
|
|
|
|
- # print(_text,end="\t")
|
|
|
|
- # print("\n")
|
|
|
|
|
|
+ # print(_cell["text"])
|
|
|
|
+ # print("\n")
|
|
# print("===========")
|
|
# print("===========")
|
|
|
|
|
|
- table_bbox = (_table[0][0].get("bbox")[0],
|
|
|
|
- _table[0][0].get("bbox")[1],
|
|
|
|
- _table[-1][-1].get("bbox")[2],
|
|
|
|
- _table[-1][-1].get("bbox")[3])
|
|
|
|
-
|
|
|
|
ta = {"bbox": table_bbox, "table": _table}
|
|
ta = {"bbox": table_bbox, "table": _table}
|
|
return ta
|
|
return ta
|
|
|
|
|
|
@@ -1337,6 +1371,8 @@ def get_table_html(table):
|
|
|
|
|
|
def sort_object(obj_list, is_reverse=False):
|
|
def sort_object(obj_list, is_reverse=False):
|
|
from format_convert.convert_tree import _Table, _Image, _Sentence, _Page
|
|
from format_convert.convert_tree import _Table, _Image, _Sentence, _Page
|
|
|
|
+ obj_list = combine_object(obj_list)
|
|
|
|
+
|
|
if len(obj_list) == 0:
|
|
if len(obj_list) == 0:
|
|
return obj_list
|
|
return obj_list
|
|
if isinstance(obj_list[0], (_Table, _Sentence, _Image)):
|
|
if isinstance(obj_list[0], (_Table, _Sentence, _Image)):
|
|
@@ -1349,6 +1385,38 @@ def sort_object(obj_list, is_reverse=False):
|
|
return obj_list
|
|
return obj_list
|
|
|
|
|
|
|
|
|
|
|
|
+def combine_object(obj_list, threshold=5):
|
|
|
|
+ from format_convert.convert_tree import _Sentence
|
|
|
|
+ sentence_list = []
|
|
|
|
+ for obj in obj_list:
|
|
|
|
+ if isinstance(obj, _Sentence):
|
|
|
|
+ obj.content = re.sub("\s", "", obj.content)
|
|
|
|
+ sentence_list.append(obj)
|
|
|
|
+ sentence_list.sort(key=lambda x: (x.y, x.x))
|
|
|
|
+ for sen in sentence_list:
|
|
|
|
+ obj_list.remove(sen)
|
|
|
|
+
|
|
|
|
+ delete_list = []
|
|
|
|
+ for i in range(1, len(sentence_list)):
|
|
|
|
+ sen1 = sentence_list[i-1]
|
|
|
|
+ sen2 = sentence_list[i]
|
|
|
|
+ if abs(sen2.y - sen1.y) <= threshold:
|
|
|
|
+ if sen2.x > sen1.x:
|
|
|
|
+ sen2.x = sen1.x
|
|
|
|
+ sen2.content = sen1.content + sen2.content
|
|
|
|
+ else:
|
|
|
|
+ sen2.content = sen2.content + sen1.content
|
|
|
|
+ if sen2.y > sen1.y:
|
|
|
|
+ sen2.y = sen1.y
|
|
|
|
+ delete_list.append(sen1)
|
|
|
|
+
|
|
|
|
+ for sen in delete_list:
|
|
|
|
+ sentence_list.remove(sen)
|
|
|
|
+ for sen in sentence_list:
|
|
|
|
+ obj_list.append(sen)
|
|
|
|
+ return obj_list
|
|
|
|
+
|
|
|
|
+
|
|
session_ocr = requests.Session()
|
|
session_ocr = requests.Session()
|
|
session_otr = requests.Session()
|
|
session_otr = requests.Session()
|
|
session_all = requests.Session()
|
|
session_all = requests.Session()
|
|
@@ -1444,48 +1512,60 @@ def get_ip_port(node_type=None, interface_type=None):
|
|
|
|
|
|
ip_port_dict = {}
|
|
ip_port_dict = {}
|
|
params = parse_yaml()
|
|
params = parse_yaml()
|
|
|
|
+ # 循环 master slave
|
|
for type1 in node_type_list:
|
|
for type1 in node_type_list:
|
|
node_type = type1.upper()
|
|
node_type = type1.upper()
|
|
ip_list = params.get(node_type).get("ip")
|
|
ip_list = params.get(node_type).get("ip")
|
|
- for type2 in interface_type_list:
|
|
|
|
- interface_type = type2.upper()
|
|
|
|
- processes = 0
|
|
|
|
- python_path = None
|
|
|
|
- project_path = None
|
|
|
|
- if interface_type in ["convert".upper()]:
|
|
|
|
- _port = params.get(node_type).get(interface_type).get("port")
|
|
|
|
- if _port is None:
|
|
|
|
- port_list = []
|
|
|
|
- else:
|
|
|
|
- if interface_type == "convert".upper():
|
|
|
|
- processes = params.get(node_type).get(interface_type).get("processes")
|
|
|
|
- port_list = [str(_port)]*int(processes)
|
|
|
|
- # port_list = [str(_port)]
|
|
|
|
- elif interface_type == "path".upper():
|
|
|
|
- python_path = params.get(node_type).get(interface_type).get("python")
|
|
|
|
- project_path = params.get(node_type).get(interface_type).get("project")
|
|
|
|
|
|
+
|
|
|
|
+ # 循环多个IP
|
|
|
|
+ for j in range(len(ip_list)):
|
|
|
|
+ _ip = ip_list[j]
|
|
|
|
+ if ip_port_dict.get(_ip):
|
|
|
|
+ ip_port_dict.get(_ip).update({node_type: {}})
|
|
else:
|
|
else:
|
|
- port_start = params.get(node_type).get(interface_type).get("port_start")
|
|
|
|
- port_no = params.get(node_type).get(interface_type).get("port_no")
|
|
|
|
- if port_start is None or port_no is None:
|
|
|
|
- port_list = []
|
|
|
|
|
|
+ ip_port_dict.update({_ip: {node_type: {}}})
|
|
|
|
+
|
|
|
|
+ # 有IP时,循环多个参数
|
|
|
|
+ for type2 in interface_type_list:
|
|
|
|
+ python_path = None
|
|
|
|
+ project_path = None
|
|
|
|
+ gunicorn_path = None
|
|
|
|
+ processes = 0
|
|
|
|
+ port_list = []
|
|
|
|
+ interface_type = type2.upper()
|
|
|
|
+ if interface_type in ["convert".upper()]:
|
|
|
|
+ _port = params.get(node_type).get(interface_type).get("port")
|
|
|
|
+ if _port is None:
|
|
|
|
+ port_list = []
|
|
|
|
+ else:
|
|
|
|
+ if interface_type == "convert".upper():
|
|
|
|
+ processes = params.get(node_type).get(interface_type).get("processes")[j]
|
|
|
|
+ port_list = [str(_port[j])]*int(processes)
|
|
|
|
+ # port_list = [str(_port)]
|
|
|
|
+ elif interface_type == "path".upper():
|
|
|
|
+ python_path = params.get(node_type).get(interface_type).get("python")[j]
|
|
|
|
+ project_path = params.get(node_type).get(interface_type).get("project")[j]
|
|
|
|
+ gunicorn_path = params.get(node_type).get(interface_type).get("gunicorn")[j]
|
|
else:
|
|
else:
|
|
- port_list = [str(x) for x in range(port_start, port_start+port_no, 1)]
|
|
|
|
- if ip_list:
|
|
|
|
- for _ip in ip_list:
|
|
|
|
- if _ip is None:
|
|
|
|
- continue
|
|
|
|
- if _ip in ip_port_dict.keys():
|
|
|
|
- if port_list:
|
|
|
|
- ip_port_dict.get(_ip).update({interface_type.lower(): port_list})
|
|
|
|
|
|
+ port_start = params.get(node_type).get(interface_type).get("port_start")
|
|
|
|
+ port_no = params.get(node_type).get(interface_type).get("port_no")
|
|
|
|
+ if port_start is None or port_no is None:
|
|
|
|
+ port_list = []
|
|
else:
|
|
else:
|
|
- if port_list:
|
|
|
|
- ip_port_dict[_ip] = {interface_type.lower(): port_list}
|
|
|
|
- if processes:
|
|
|
|
- ip_port_dict.get(_ip).update({interface_type.lower()+"_processes": processes})
|
|
|
|
- if project_path and python_path:
|
|
|
|
- ip_port_dict.get(_ip).update({"project_path": project_path,
|
|
|
|
- "python_path": python_path})
|
|
|
|
|
|
+ port_list = [str(x) for x in range(port_start[j], port_start[j]+port_no[j], 1)]
|
|
|
|
+ # if ip_list:
|
|
|
|
+ # for i in range(len(ip_list)):
|
|
|
|
+
|
|
|
|
+ # 参数放入dict
|
|
|
|
+ if port_list:
|
|
|
|
+ ip_port_dict.get(_ip).get(node_type).update({interface_type.lower(): port_list})
|
|
|
|
+ if processes:
|
|
|
|
+ ip_port_dict.get(_ip).get(node_type).update({interface_type.lower()+"_processes": processes})
|
|
|
|
+ if project_path and python_path and gunicorn_path:
|
|
|
|
+ ip_port_dict.get(_ip).get(node_type).update({"project_path": project_path,
|
|
|
|
+ "python_path": python_path,
|
|
|
|
+ "gunicorn_path": gunicorn_path})
|
|
|
|
+ # print("ip_port_dict", ip_port_dict)
|
|
return ip_port_dict
|
|
return ip_port_dict
|
|
|
|
|
|
|
|
|
|
@@ -1582,7 +1662,10 @@ def set_flask_global():
|
|
"convert": 0,
|
|
"convert": 0,
|
|
"office": 0
|
|
"office": 0
|
|
}})
|
|
}})
|
|
- ip_flag.append([_k, 0])
|
|
|
|
|
|
+ if ip_port_dict.get(_k).get("MASTER"):
|
|
|
|
+ ip_flag.append([_k+"_master", 0])
|
|
|
|
+ if ip_port_dict.get(_k).get("SLAVE"):
|
|
|
|
+ ip_flag.append([_k+"_slave", 0])
|
|
_global.update({"ip_port_flag": ip_port_flag})
|
|
_global.update({"ip_port_flag": ip_port_flag})
|
|
_global.update({"ip_port": ip_port_dict})
|
|
_global.update({"ip_port": ip_port_dict})
|
|
_global.update({"ip_flag": ip_flag})
|
|
_global.update({"ip_flag": ip_flag})
|
|
@@ -1611,6 +1694,116 @@ def get_md5_from_bytes(_bytes):
|
|
return None, _length
|
|
return None, _length
|
|
|
|
|
|
|
|
|
|
|
|
+# def to_share_memory(np_data, name=None):
|
|
|
|
+# # from multiprocessing.resource_tracker import unregister
|
|
|
|
+# from multiprocessing import shared_memory
|
|
|
|
+# if name is None:
|
|
|
|
+# sm_name = "psm_" + str(os.getpid())
|
|
|
|
+# else:
|
|
|
|
+# sm_name = name
|
|
|
|
+# logging.info("into from_share_memory sm_name " + sm_name)
|
|
|
|
+# shm = shared_memory.SharedMemory(name=sm_name, create=True, size=np_data.nbytes)
|
|
|
|
+# # unregister(sm_name, 'shared_memory')
|
|
|
|
+# sm_data = np.ndarray(np_data.shape, dtype=np_data.dtype, buffer=shm.buf)
|
|
|
|
+# sm_data[:] = np_data[:] # Copy the original data into shared memory
|
|
|
|
+#
|
|
|
|
+# shm.close()
|
|
|
|
+# del sm_data
|
|
|
|
+# return shm
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+# def from_share_memory(sm_name, _shape, _dtype, if_close=True):
|
|
|
|
+# from multiprocessing import shared_memory
|
|
|
|
+# logging.info("into from_share_memory sm_name " + sm_name)
|
|
|
|
+# shm = shared_memory.SharedMemory(name=sm_name, create=False)
|
|
|
|
+# b = np.ndarray(_shape, dtype=_dtype, buffer=shm.buf)
|
|
|
|
+# sm_data = copy.deepcopy(b)
|
|
|
|
+# b[::] = 0
|
|
|
|
+#
|
|
|
|
+# if if_close:
|
|
|
|
+# try:
|
|
|
|
+# shm.close()
|
|
|
|
+# shm.unlink()
|
|
|
|
+# except Exception:
|
|
|
|
+# log("file not found! " + sm_name)
|
|
|
|
+# return sm_data
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+# def get_share_memory(sm_name):
|
|
|
|
+# try:
|
|
|
|
+# from multiprocessing import shared_memory
|
|
|
|
+# shm = shared_memory.SharedMemory(name=sm_name, create=False)
|
|
|
|
+# return shm
|
|
|
|
+# except:
|
|
|
|
+# return None
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+# def release_share_memory(shm):
|
|
|
|
+# try:
|
|
|
|
+# if shm is None:
|
|
|
|
+# return
|
|
|
|
+# shm.close()
|
|
|
|
+# shm.unlink()
|
|
|
|
+# log(str(shm.name) + " release successfully!")
|
|
|
|
+# except FileNotFoundError:
|
|
|
|
+# log(str(shm.name) + " has released!")
|
|
|
|
+# except Exception as e:
|
|
|
|
+# traceback.print_exc()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+# def get_share_memory_list(sm_list_name, list_size=None):
|
|
|
|
+# # from multiprocessing.resource_tracker import unregister
|
|
|
|
+# from multiprocessing import shared_memory
|
|
|
|
+# if list_size is None:
|
|
|
|
+# sm_list = shared_memory.ShareableList(name=sm_list_name)
|
|
|
|
+# else:
|
|
|
|
+# sm_list = shared_memory.ShareableList(name=sm_list_name, sequence=["0"]+[' '*2048]*(list_size-2)+["0"])
|
|
|
|
+# # unregister(sm_list_name, 'shared_memory')
|
|
|
|
+# return sm_list
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+# def close_share_memory_list(sm_list):
|
|
|
|
+# try:
|
|
|
|
+# sm_list.shm.close()
|
|
|
|
+# except Exception:
|
|
|
|
+# traceback.print_exc()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def get_np_type(_str):
|
|
|
|
+ _dtype = None
|
|
|
|
+ if _str == 'uint8':
|
|
|
|
+ _dtype = np.uint8
|
|
|
|
+ elif _str == 'float16':
|
|
|
|
+ _dtype = np.float16
|
|
|
|
+ elif _str == 'float32':
|
|
|
|
+ _dtype = np.float32
|
|
|
|
+ logging.info("get_np_type " + _str + " " + str(_dtype))
|
|
|
|
+ return _dtype
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def namespace_to_dict(agrs_or_dict, reverse=False):
|
|
|
|
+ if reverse:
|
|
|
|
+ agrs_or_dict = argparse.Namespace(**agrs_or_dict)
|
|
|
|
+ else:
|
|
|
|
+ agrs_or_dict = vars(agrs_or_dict)
|
|
|
|
+ return agrs_or_dict
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def get_args_from_config(ip_port_dict, ip, arg_type, node_type=None):
|
|
|
|
+ if node_type is None:
|
|
|
|
+ node_type = ["MASTER", "SLAVE"]
|
|
|
|
+ else:
|
|
|
|
+ node_type = [node_type]
|
|
|
|
+
|
|
|
|
+ arg_list = []
|
|
|
|
+ for _type in node_type:
|
|
|
|
+ if ip_port_dict.get(ip).get(_type):
|
|
|
|
+ if ip_port_dict.get(ip).get(_type).get(arg_type):
|
|
|
|
+ arg_list.append(ip_port_dict.get(ip).get(_type).get(arg_type))
|
|
|
|
+
|
|
|
|
+ return arg_list
|
|
|
|
+
|
|
|
|
+
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
# strs = r"D:\Project\temp\04384fcc9e8911ecbd2844f971944973\043876ca9e8911eca5e144f971944973_rar\1624114035529.jpeg"
|
|
# strs = r"D:\Project\temp\04384fcc9e8911ecbd2844f971944973\043876ca9e8911eca5e144f971944973_rar\1624114035529.jpeg"
|
|
# print(slash_replace(strs))
|
|
# print(slash_replace(strs))
|
|
@@ -1639,6 +1832,6 @@ if __name__ == "__main__":
|
|
|
|
|
|
# print(parse_yaml())
|
|
# print(parse_yaml())
|
|
|
|
|
|
- print(get_ip_port(node_type='slave'))
|
|
|
|
-
|
|
|
|
|
|
+ print(get_ip_port())
|
|
|
|
+ print(get_args_from_config(get_ip_port(), "http://127.0.0.1", "gunicorn_path"))
|
|
# print(get_intranet_ip())
|
|
# print(get_intranet_ip())
|