RuntimeError: can't start new thread


I’m trying to build a docker image via Jenkins and it is continuously getting failed saying that “RuntimeError: can’t start new thread” . Below are my docker file and requirements file content. Since I’m very new to docker, it will be great if someone can guide me on resolving this error.

I’m currently using docker version 24.0.6, build ed223bc

Docker file:

FROM python:3.9-slim
COPY . .
RUN pip install -r ‘requirements.txt’
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
ENTRYPOINT [“streamlit”, “run”, “”, “–server.port=8501”, “–server.address=”]




Status: Downloaded newer image for python:3.9-slim
—> 0540301f15db
Step 2/7 : WORKDIR /app
—> Running in d788cbe7b39a
Removing intermediate container d788cbe7b39a
—> 935037a4877e
Step 3/7 : COPY . .
—> fd81d949066b
Step 4/7 : RUN pip3 install -r requirements.txt
—> Running in c75f005d7e95
Collecting streamlit
Downloading streamlit-1.27.2-py2.py3-none-any.whl (7.6 MB)
ERROR: Exception:
Traceback (most recent call last):
File “/usr/local/lib/python3.9/site-packages/pip/_internal/cli/”, line 160, in exc_logging_wrapper
status = run_func(*args)
File “/usr/local/lib/python3.9/site-packages/pip/_internal/cli/”, line 247, in wrapper
return func(self, options, args)
File “/usr/local/lib/python3.9/site-packages/pip/_internal/commands/”, line 419, in run
requirement_set = resolver.resolve(
File “/usr/local/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/”, line 92, in resolve
result = self._result = resolver.resolve(
File “/usr/local/lib/python3.9/site-packages/pip/_vendor/resolvelib/”, line 481, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File “/usr/local/lib/python3.9/site-packages/pip/_vendor/resolvelib/”, line 348, in resolve
self._add_to_criteria(self.state.criteria, r, parent=None)
File “/usr/local/lib/python3.9/site-packages/pip/_vendor/resolvelib/”, line 172, in _add_to_criteria
if not criterion.candidates:
File “/usr/local/lib/python3.9/site-packages/pip/_vendor/resolvelib/”, line 151, in bool
return bool(self._sequence)
File “/usr/local/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/”, line 155, in bool
return any(self)
File “/usr/local/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/”, line 143, in
return (c for c in iterator if id(c) not in self._incompatible_ids)
File “/usr/local/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/”, line 47, in _iter_built
candidate = func()
File “/usr/local/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/”, line 206, in _make_candidate_from_link
self._link_candidate_cache[link] = LinkCandidate(
File “/usr/local/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/”, line 297, in init
File “/usr/local/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/”, line 162, in init
self.dist = self._prepare()
File “/usr/local/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/”, line 231, in _prepare
dist = self._prepare_distribution()
File “/usr/local/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/”, line 308, in _prepare_distribution
return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
File “/usr/local/lib/python3.9/site-packages/pip/_internal/operations/”, line 491, in prepare_linked_requirement
return self._prepare_linked_requirement(req, parallel_builds)
File “/usr/local/lib/python3.9/site-packages/pip/_internal/operations/”, line 536, in _prepare_linked_requirement
local_file = unpack_url(
File “/usr/local/lib/python3.9/site-packages/pip/_internal/operations/”, line 166, in unpack_url
file = get_http_url(
File “/usr/local/lib/python3.9/site-packages/pip/_internal/operations/”, line 107, in get_http_url
from_path, content_type = download(link, temp_dir.path)
File “/usr/local/lib/python3.9/site-packages/pip/_internal/network/”, line 147, in call
for chunk in chunks:
File “/usr/local/lib/python3.9/site-packages/pip/_internal/cli/”, line 52, in _rich_progress_bar
with progress:
File “/usr/local/lib/python3.9/site-packages/pip/_vendor/rich/”, line 1169, in enter
File “/usr/local/lib/python3.9/site-packages/pip/_vendor/rich/”, line 1160, in start
File “/usr/local/lib/python3.9/site-packages/pip/_vendor/rich/”, line 132, in start
File “/usr/local/lib/python3.9/”, line 899, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can’t start new thread

[notice] A new release of pip is available: 23.0.1 → 23.2.1
[notice] To update, run: pip install --upgrade pip

pip uses thread to show progress bar. Try to disable it:

RUN pip install --progress-bar off -r requirements.txt

1 Like

This helps me with pip install, thx!

Could you explain me pls, why i receive same error when i try to use threads\procs in my docker ( container with python).

from multiprocessing.dummy import Pool as ThreadPool


import concurrent.futures


import threading

All libs had same error:

RuntimeError: can't start new thread

I also got this problem, and after I added --privileged when do docker run, the problem fixed, hope it can help you.

Thx, it works for me! Could you tell me is that secure? What kind of problems i should expect after use that workaround?