Elyas
Elyas

Reputation: 11

Python: can't start new thread

I ran into a problem with python threading and when I started to test the maximum limit of threads I ended up with 900 threads max but when I ran this code on another pc it was ok with up to 500,000 threads

maybe something wrong with registry files !?

Platform: Windows

from threading import Thread, activeCount
from time import sleep

def x():
    sleep(1000)
    print('END')

for i in range(5000):
    Thread(target=x).start()
    print (activeCount())

and Output is :

890
891
892
893
894
895
896
897
898
Traceback (most recent call last):
  File "C:/Users/TAS02/PycharmProjects/All_Projects/tst.py", line 38, in <module>
    Thread(target=x).start()
  File "C:\Users\TAS02\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 852, in start
    _start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread

Upvotes: 0

Views: 1492

Answers (2)

Elyas
Elyas

Reputation: 11

It turned out that windows 64-bit has some problems with python 32-bit and that was the Problem in my case

Upvotes: 1

thenullptr
thenullptr

Reputation: 411

As said above, I think this is to do with OS limits. It's difficult to compare against another machine without knowing the details but things like is it 32/64bit, RAM size, OS limits can all have an impact. I suspect that python is using a lot of memory so Windows is limiting it. The link below may help you to find out what the limit is for threads. https://learn.microsoft.com/en-us/sysinternals/downloads/testlimit

Upvotes: 0

Related Questions