linux - 在 AWS Nitro Enclave 中导入 openCV 时 Python 代码挂起
问题描述
我正在尝试使用 python在AWS nitro-enclave内进行一些图像识别。但是在导入 OpenCV、NumPy 和 pandas 等包时,代码会挂起。用于构建 enclave 的 dockerfile 文件将在我的本地机器或 EC2 中正常运行。生成的 enclave 控制台将输出一些关于 L2 缓存大小和进程冻结的 openBLAS 警告。没有任何类型的错误输出。在 enclave 中使用包时是否需要添加任何其他依赖项,或者与内核存在一些冲突?
docker、shell和py测试代码如下所示:
#amazonlinux still have the import issue
#python:3.7 libs importing crush
FROM amazonlinux
WORKDIR /app
#py 3.7
RUN yum install python3 zip -y
ENV VIRTIAL_ENV=/opt/venv
RUN python3 -m venv $VIRTIAL_ENV
ENV PATH="$VIRTIAL_ENV/bin:$PATH"
#3 libs needed for cv2 import
RUN yum install libSM-1.2.2-2.amzn2.x86_64 -y
RUN yum install libXrender-0.9.10-1.amzn2.x86_64 -y
RUN yum install libXext-1.3.3-3.amzn2.x86_64 -y
COPY requirements.txt ./
RUN pip3 install --no-cache-dir -r /app/requirements.txt
#shell script testing
COPY dockerfile_entrypoint.sh ./
COPY test_cv2.py ./
#ENV for shell testing printf loop
ENV HELLO="Hello from enclave side!"
RUN chmod +X dockerfile_entrypoint.sh
#shell script testing
CMD ["/app/dockerfile_entrypoint.sh"]
#!/bin/bash
#shell printf loop test in enclave
# go to work dir and check files
cd /app||return
ls
#cv2 imp issue
python3 test_cv2.py
#use shell loop to keep enclave live to see error message output
count=1
while true;do
printf "[%4d] $HELLO\n" $count
echo "$PWD"
ls
count=$((count+1))
sleep 5
done
import cv2
for i in range(10):
print('testing OpenCV')
解决方案
当应用程序或库尝试从中读取数据/dev/random
但没有足够的熵时,可能会发生这些类型的挂起,这会导致进程在读取时阻塞。此 GitHub 问题中有一些可能的解决方案:https ://github.com/aws/aws-nitro-enclaves-sdk-c/issues/41#issuecomment-792621500