在docker容器下gunicorn是线程创建在系统层面被拒绝

问题

...
 RuntimeError: can't start new thread xxx exited with code 1

Python 进程在启动日志线程时,pthread_create() 失败了

env

  • docker-v1.13.1
  • CentOS Linux release 7.9.2009 (Core)

解决

1.检查

[root@xxx ~]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 252870
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65535
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 252870      # 用户支持最大创建进程数
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

2.升级docker

[root@xxx ~]# docker version
Client: Docker Engine - Community
 Version:           26.1.3
 API version:       1.45
 Go version:        go1.21.10
 Git commit:        b72abbb
 Built:             Thu May 16 08:34:39 2024
 OS/Arch:           linux/amd64
 Context:           default

3.启动验证

...
    CMD ["gunicorn" "-c" "gunicorn_conf.py" "app.main:app"]