代码更新
This commit is contained in:
1 parent
4e8ba476f5
commit
b663c7b31c
2 files changed
+2
-41
No files matched your search
+1
-41
@@ -18,46 +18,6 @@ from config import print_data_dir
|
|||||||
|
|
||||||
from general import is_run_local_data
|
from general import is_run_local_data
|
||||||
|
|
||||||
def find_free_display():
|
|
||||||
"""
|
|
||||||
寻找一个可用的显示编号。
|
|
||||||
从 99 开始尝试,最大尝试到 199。
|
|
||||||
"""
|
|
||||||
display_num = 99
|
|
||||||
max_attempts = 100 # 最大尝试次数,避免无限循环
|
|
||||||
|
|
||||||
for attempt in range(max_attempts):
|
|
||||||
display = f":{display_num}"
|
|
||||||
lock_file = f"/tmp/.X{display_num}-lock"
|
|
||||||
|
|
||||||
# 检查锁文件是否存在
|
|
||||||
if os.path.exists(lock_file):
|
|
||||||
print(f"显示设备 {display} 被锁定,尝试下一个...")
|
|
||||||
display_num += 1
|
|
||||||
continue
|
|
||||||
|
|
||||||
# 尝试启动一个短暂的Xvfb进程来测试端口是否真的空闲
|
|
||||||
test_proc = subprocess.Popen(
|
|
||||||
["Xvfb", display, "-screen", "0", "1x1x1"],
|
|
||||||
stdout=subprocess.DEVNULL,
|
|
||||||
stderr=subprocess.PIPE
|
|
||||||
)
|
|
||||||
sleep(0.5) # 稍等片刻
|
|
||||||
|
|
||||||
# 如果进程很快结束了,通常意味着启动失败(可能是端口被占用或其他错误)
|
|
||||||
return_code = test_proc.poll()
|
|
||||||
if return_code is not None:
|
|
||||||
# 启动失败,尝试下一个端口
|
|
||||||
display_num += 1
|
|
||||||
test_proc.terminate()
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
# 启动成功!终止测试进程,并返回这个可用的显示编号
|
|
||||||
test_proc.terminate()
|
|
||||||
return display_num
|
|
||||||
|
|
||||||
raise RuntimeError(f"在尝试了 {max_attempts} 次后,未能找到可用的显示设备端口。")
|
|
||||||
|
|
||||||
# 如果没有 DISPLAY,自动启动 Xvfb
|
# 如果没有 DISPLAY,自动启动 Xvfb
|
||||||
if "DISPLAY" not in os.environ:
|
if "DISPLAY" not in os.environ:
|
||||||
import atexit
|
import atexit
|
||||||
@@ -69,7 +29,7 @@ if "DISPLAY" not in os.environ:
|
|||||||
os.environ["XDG_RUNTIME_DIR"] = runtime_dir
|
os.environ["XDG_RUNTIME_DIR"] = runtime_dir
|
||||||
|
|
||||||
# 使用函数查找空闲的显示端口
|
# 使用函数查找空闲的显示端口
|
||||||
free_display_num = find_free_display()
|
free_display_num = 99
|
||||||
display_env = f":{free_display_num}"
|
display_env = f":{free_display_num}"
|
||||||
|
|
||||||
# 启动 Xvfb,使用找到的空闲端口
|
# 启动 Xvfb,使用找到的空闲端口
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ url_get_oss_suffix_by_orderId = f"https://mp.api.suwa3d.com/api/order/getOssSuff
|
|||||||
|
|
||||||
# -------------------------- 开始:路径配置 -------------------------------
|
# -------------------------- 开始:路径配置 -------------------------------
|
||||||
|
|
||||||
|
# print_factory_type_dir="/root/git/"
|
||||||
# print_factory_type_dir="/home/ecs-user/git/"
|
# print_factory_type_dir="/home/ecs-user/git/"
|
||||||
print_factory_type_dir = "/home/algo/Documents/print_factory_type/git"
|
print_factory_type_dir = "/home/algo/Documents/print_factory_type/git"
|
||||||
print_data_dir = f"{print_factory_type_dir}/data/"
|
print_data_dir = f"{print_factory_type_dir}/data/"
|
||||||
|
|||||||
Reference in new issue
Block a user