# RuntimeError: can't start new thread

**URL:** <https://forums.docker.com/t/runtimeerror-cant-start-new-thread/138142>\
**Category:** Docker Desktop\
**Tags:** docker, build, windows\
**Created:** [October 19, 2023, 6:37am UTC](https://forums.docker.com/t/runtimeerror-cant-start-new-thread/138142 "2023-10-19T06:37:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gowjayac072](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gowjayac072](https://forums.docker.com/u/gowjayac072)\
**Post date:** [October 19, 2023, 6:37am UTC](https://forums.docker.com/t/runtimeerror-cant-start-new-thread/138142/1 "2023-10-19T06:37:23Z")

</div>

Hi,

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  
WORKDIR /app  
COPY . .  
RUN pip install -r ‘requirements.txt’  
EXPOSE 8501  
HEALTHCHECK CMD curl --fail [http://localhost:8501/\_stcore/health](http://localhost:8501/_stcore/health)  
ENTRYPOINT [“streamlit”, “run”, “CustomerSupport8.py”, “–server.port=8501”, “–server.address=0.0.0.0”]

**Requirements.txt**

openai==0.28.1  
streamlit==1.27.0  
langchain==0.0.316  
numpy==1.18.0  
pandas==2.0.3  
pypdf==3.7.0  
streamlit-chat==0.1.1  
tiktoken==0.3.2  
faiss-cpu==1.7.1

**Error:**

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/base\_command.py”, line 160, in exc\_logging\_wrapper  
status = run\_func(\*args)  
File “/usr/local/lib/python3.9/site-packages/pip/\_internal/cli/req\_command.py”, line 247, in wrapper  
return func(self, options, args)  
File “/usr/local/lib/python3.9/site-packages/pip/\_internal/commands/install.py”, line 419, in run  
requirement\_set = resolver.resolve(  
File “/usr/local/lib/python3.9/site-packages/pip/\_internal/resolution/resolvelib/resolver.py”, line 92, in resolve  
result = self.\_result = resolver.resolve(  
File “/usr/local/lib/python3.9/site-packages/pip/\_vendor/resolvelib/resolvers.py”, line 481, in resolve  
state = resolution.resolve(requirements, max\_rounds=max\_rounds)  
File “/usr/local/lib/python3.9/site-packages/pip/\_vendor/resolvelib/resolvers.py”, 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/resolvers.py”, line 172, in \_add\_to\_criteria  
if not criterion.candidates:  
File “/usr/local/lib/python3.9/site-packages/pip/\_vendor/resolvelib/structs.py”, line 151, in **bool**  
return bool(self.\_sequence)  
File “/usr/local/lib/python3.9/site-packages/pip/\_internal/resolution/resolvelib/found\_candidates.py”, line 155, in **bool**  
return any(self)  
File “/usr/local/lib/python3.9/site-packages/pip/\_internal/resolution/resolvelib/found\_candidates.py”, 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/found\_candidates.py”, line 47, in \_iter\_built  
candidate = func()  
File “/usr/local/lib/python3.9/site-packages/pip/\_internal/resolution/resolvelib/factory.py”, 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/candidates.py”, line 297, in **init**  
super(). **init** (  
File “/usr/local/lib/python3.9/site-packages/pip/\_internal/resolution/resolvelib/candidates.py”, line 162, in **init**  
self.dist = self.\_prepare()  
File “/usr/local/lib/python3.9/site-packages/pip/\_internal/resolution/resolvelib/candidates.py”, line 231, in \_prepare  
dist = self.\_prepare\_distribution()  
File “/usr/local/lib/python3.9/site-packages/pip/\_internal/resolution/resolvelib/candidates.py”, 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/prepare.py”, 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/prepare.py”, line 536, in \_prepare\_linked\_requirement  
local\_file = unpack\_url(  
File “/usr/local/lib/python3.9/site-packages/pip/\_internal/operations/prepare.py”, line 166, in unpack\_url  
file = get\_http\_url(  
File “/usr/local/lib/python3.9/site-packages/pip/\_internal/operations/prepare.py”, 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/download.py”, line 147, in **call**  
for chunk in chunks:  
File “/usr/local/lib/python3.9/site-packages/pip/\_internal/cli/progress\_bars.py”, line 52, in \_rich\_progress\_bar  
with progress:  
File “/usr/local/lib/python3.9/site-packages/pip/\_vendor/rich/progress.py”, line 1169, in **enter**  
self.start()  
File “/usr/local/lib/python3.9/site-packages/pip/\_vendor/rich/progress.py”, line 1160, in start  
self.live.start(refresh=True)  
File “/usr/local/lib/python3.9/site-packages/pip/\_vendor/rich/live.py”, line 132, in start  
self.\_refresh\_thread.start()  
File “/usr/local/lib/python3.9/threading.py”, 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

---

<div class="post-metadata">

**Author:** ![asofyan](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/asofyan/32/43210_2.png) [@asofyan](https://forums.docker.com/u/asofyan)\
**Post date:** [November 11, 2023, 1:28am UTC](https://forums.docker.com/t/runtimeerror-cant-start-new-thread/138142/2 "2023-11-11T01:28:04Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![twobytwohandsofblue](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/twobytwohandsofblue/32/43340_2.png) [@twobytwohandsofblue](https://forums.docker.com/u/twobytwohandsofblue)\
**Post date:** [November 15, 2023, 2:48pm UTC](https://forums.docker.com/t/runtimeerror-cant-start-new-thread/138142/3 "2023-11-15T14:48:20Z")

</div>

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).

```auto
from multiprocessing.dummy import Pool as ThreadPool

```

or

```auto
import concurrent.futures

```

or

```auto
import threading

```

All libs had same error:

```auto
RuntimeError: can't start new thread

```

---

<div class="post-metadata">

**Author:** ![czguang](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@czguang](https://forums.docker.com/u/czguang)\
**Post date:** [November 16, 2023, 12:18pm UTC](https://forums.docker.com/t/runtimeerror-cant-start-new-thread/138142/4 "2023-11-16T12:18:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![twobytwohandsofblue](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/twobytwohandsofblue/32/43340_2.png) [@twobytwohandsofblue](https://forums.docker.com/u/twobytwohandsofblue)\
**Post date:** [November 21, 2023, 1:22pm UTC](https://forums.docker.com/t/runtimeerror-cant-start-new-thread/138142/5 "2023-11-21T13:22:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zijianchenhandsome](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/zijianchenhandsome/32/55051_2.png) [@zijianchenhandsome](https://forums.docker.com/u/zijianchenhandsome)\
**Post date:** [December 26, 2024, 2:15am UTC](https://forums.docker.com/t/runtimeerror-cant-start-new-thread/138142/6 "2024-12-26T02:15:47Z")

</div>

cheers mate, my code work aftering trying that!!!
