报错细节:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "<stdin>", line 2, in <dictcomp>
  File "/usr/lib64/python3.8/concurrent/futures/thread.py", line 188, in submit
    self._adjust_thread_count()
  File "/usr/lib64/python3.8/concurrent/futures/thread.py", line 213, in _adjust_thread_count
    t.start()
  File "/usr/lib64/python3.8/threading.py", line 852, in start
    _start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread

错误原因:docker版本过低(version 20.x)而容器对应的基础镜像版本过高,如Ubuntu22.04、Debian12等,执行程序时程序无法多线程执行。可参考:

This is because the default seccomp profile of Docker 20.10.9 is not adjusted to support the clone() syscall wrapper of glibc 2.34 adopted in Ubuntu 21.10 and Fedora 35.

 解决方法:

1、拉取低版本的镜像(Ubuntu20.04及以下版本、Debian11及以下版本),使用新镜像重新运行封装容器(推荐:不会影响已有的docker镜像与容器),如:

# 原始的高版本镜像
docker pull bitnami/pytorch:latest
docker pull bitnami/pytorch:2.2.2-debian-12-r0

# 新拉取的低版本镜像
docker pull bitnami/pytorch:2.0.0-debian-11-r0

2、卸载旧版本的docker,安装/升级docker至新版本(version 21.x以上),重新运行容器(不推荐:新版本安装过程时间长且容易带来其它问题,可能影响已有的docker镜像与容器);

sudo apt-get upgrade docker-ce

3、安装时,去除进度条显示(不推荐:去除进度条显示(关闭了进度条显示线程)只是保证pip在安装时仅有一个安装线程在执行,当再执行其它多线程程序时还会报其它错误)

# 一次性操作
pip install --progress-bar off opencv-python

# 永久操作
pip config --user set global.progress_bar off

参考博客:在docker中运行 pip 报错 Can‘t start new thread_docker can't start new thread-CSDN博客

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐