Skip to content

Commit 8dfc89a

Browse files
committed
feat(hikyuu): 移除vcomp140.dll检查并添加OpenMP配置选项
同时在xmake构建系统中添加了omp配置选项,默认关闭OpenMP支持, 因为在数据不在内存中时容易导致CPU占用过高,建议仅在调试时使用。
1 parent 4e57715 commit 8dfc89a

File tree

3 files changed

+14
-56
lines changed

3 files changed

+14
-56
lines changed

hikyuu/__init__.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -37,51 +37,6 @@
3737
BASE_DIR = os.path.dirname(__file__)
3838

3939

40-
def check_vcomp_available(vcomp_dll_name: str = "vcomp140.dll") -> tuple[bool, str]:
41-
"""
42-
check if the current Python environment can load the specified vcomp DLL
43-
:param vcomp_dll_name: The name of the vcomp DLL to detect (e.g., vcomp140.dll, vcomp143.dll)
44-
:return: (Availability, Description of detection results)
45-
"""
46-
search_paths = []
47-
search_paths.append(os.getcwd())
48-
search_paths.append(os.path.dirname(sys.executable))
49-
search_paths.append(os.path.join(os.environ["WINDIR"], "System32"))
50-
search_paths.extend(os.environ["PATH"].split(os.pathsep))
51-
52-
# 步骤3:遍历路径检查DLL文件是否存在
53-
dll_full_path = None
54-
for path in search_paths:
55-
candidate = os.path.join(path, vcomp_dll_name)
56-
candidate = os.path.normpath(candidate)
57-
if os.path.exists(candidate) and os.path.isfile(candidate):
58-
dll_full_path = candidate
59-
break
60-
61-
if not dll_full_path:
62-
return (False, f"Not found: {vcomp_dll_name}! serch path: {search_paths}\n")
63-
64-
try:
65-
from ctypes import WinDLL
66-
vcomp_dll = WinDLL(dll_full_path)
67-
has_core_func = hasattr(vcomp_dll, "_vcomp_get_thread_num")
68-
if has_core_func:
69-
return (True, f"Success loaded {vcomp_dll_name}! path: {dll_full_path}\n")
70-
else:
71-
return (False, f"{vcomp_dll_name} The file exists, but there is no core export function (it may be a tampered/incorrect version)")
72-
except OSError as e:
73-
error_code = e.winerror if hasattr(e, "winerror") else -1
74-
if error_code == 126:
75-
msg = "The specified module cannot be found (DLL file is corrupted/missing dependencies)"
76-
elif error_code == 193:
77-
msg = "%1 is not a valid Win32 application (bit mismatch, such as a 32-bit DLL loaded in 64-bit Python)"
78-
else:
79-
msg = f"Failed to load, Windows error code: {error_code}, description: {e.strerror}"
80-
return (False, f"Failed load {vcomp_dll_name}! path: {dll_full_path}\n errmsg: {msg}\n")
81-
except Exception as e:
82-
return (False, f"Failed load {vcomp_dll_name}! {str(e)}")
83-
84-
8540
if sys.platform == 'win32':
8641
# add_dll_directory() 有时不生效
8742
os.add_dll_directory(os.path.join(os.path.dirname(__file__), 'cpp'))
@@ -90,11 +45,6 @@ def check_vcomp_available(vcomp_dll_name: str = "vcomp140.dll") -> tuple[bool, s
9045
dll_directory = os.path.join(BASE_DIR, 'cpp')
9146
new_path = f"{dll_directory};{current_path}"
9247
os.environ['PATH'] = new_path
93-
94-
available, message = check_vcomp_available("vcomp140.dll")
95-
if not available:
96-
print(message)
97-
print("缺失 vcomp140.dll, 需要安装VC运行时, Microsoft 地址:https://aka.ms/vc14/vc_redist.x64.exe")
9848
else:
9949
current_path = os.environ.get('LD_LIBRARY_PATH', '')
10050
dll_directory = os.path.join(BASE_DIR, 'cpp')

hikyuu_cpp/hikyuu/xmake.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ target("hikyuu")
1414
end
1515
end
1616

17-
add_packages("boost", "fmt", "spdlog", "flatbuffers", "nng", "nlohmann_json", "xxhash", "eigen", "openmp")
17+
add_packages("boost", "fmt", "spdlog", "flatbuffers", "nng", "nlohmann_json", "xxhash", "eigen")
1818
if is_plat("windows", "linux", "cross", "macosx") then
1919
if get_config("sqlite") or get_config("hdf5") then
2020
add_packages("sqlite3")
2121
end
2222
end
2323

24-
if is_plat("macosx") then
25-
add_packages("libomp")
24+
if has_config("omp") then
25+
add_packages("openmp")
26+
if is_plat("macosx") then
27+
add_packages("libomp")
28+
end
2629
end
2730

2831
if has_config("http_client_zip") then

xmake.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ option("log_level", {description = "set log level.", default = 2, values = {1, 2
3838
option("async_log", {description = "Use async log.", default = false})
3939
option("leak_check", {description = "Enable leak check for test", default = false})
4040

41+
-- openmp 默认关闭,omp容易在数据不是全部在内存中时容易CPU占满空等,建议调测时使用
42+
option("omp", {description = "Enable openmp support.", default = false})
43+
4144
-- 不再直接包含 arrow, 此处保留仅作编译兼容,实际不再使用
4245
option("arrow", {description = "Enable arrow support.(Obsolete, kept only for compatibility)", default = false})
4346

@@ -190,9 +193,11 @@ add_requires("eigen", {system = false})
190193
add_requires("xxhash", {system = false})
191194
add_requires("utf8proc 2.11.0", {system = false})
192195

193-
add_requires("openmp", {system = false})
194-
if is_plat("macosx") then
195-
add_requires("libomp", {system = false})
196+
if has_config("omp") then
197+
add_requires("openmp", {system = false})
198+
if is_plat("macosx") then
199+
add_requires("libomp", {system = false})
200+
end
196201
end
197202

198203
if has_config("http_client_zip") then

0 commit comments

Comments
 (0)