Python in docker – RuntimeError: can't start new thread

Python in docker – RuntimeError: can't start new thread

我无法自己调试一个错误。我在 Fedora 版本 35(三十五)的 docker 图像中 运行ning python 3.8.12,我无法从 python 生成线程。 boto3 并行传输到 运行 是必需的,它使用 concurrent.features 来实现。

在没有任何依赖性的情况下复制我的问题的最简单示例是 (copied from python docs)

import concurrent.futures
import urllib.request

URLS = ['http://www.foxnews.com/',
        'http://www.cnn.com/',
        'http://europe.wsj.com/',
        'http://www.bbc.co.uk/',
        'http://some-made-up-domain.com/']

def load_url(url, timeout):
    with urllib.request.urlopen(url, timeout=timeout) as conn:
        return conn.read()

with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
    future_to_url = {executor.submit(load_url, url, 60): url for url in URLS}
    for future in concurrent.futures.as_completed(future_to_url):
        url = future_to_url[future]
        try:
            data = future.result()
        except Exception as exc:
            pass

遗憾的是这些行的输出是

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

我只有这些。有应该看的地方吗?我已经检查过 ulimit,上面写着 unlimited。我有点绝望去哪里查看或更改什么来调试此问题。

此问题的解决方案是将 docker 从版本 18.06.1-ce 升级到 20.10.7。

为什么?

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.

来源:ubuntu:21.10 and fedora:35 do not work on the latest Docker (20.10.9)