thread limit in python

danieldsmith at gmail.com danieldsmith at gmail.com
Thu Aug 11 18:52:24 CEST 2005


hello all,

i have run into a problem where i cannot start more than 1021 threads
in a python program, no matter what my ulimit or kernel settings are.
my program crashes with 'thread.error: can't start new thread' when it
tries to start the 1021st thread.

in addition to tweaking my ulimit settings, i have also verified that
the version of glibc i'm using has PTHREAD_THREADS_MAX defined to be
16374.  i have posted my test program below as well as the ulimit
settings i was running it with.  any help would be greatly appreciated.


thanks in advance,
dan smith

<program>
import os
import sys
import time
import threading

num_threads = int(sys.argv[1])

def run ():
   # just sleep
   time.sleep(10000)

for i in range(1,num_threads+1):

   print 'starting thread %d' %i
   t=threading.Thread (None, run)

   t.start()

os._exit(1)
</program>

<ulimit -a>
core file size        (blocks, -c) 0
data seg size         (kbytes, -d) unlimited
file size             (blocks, -f) unlimited
max locked memory     (kbytes, -l) 4
max memory size       (kbytes, -m) unlimited
open files                    (-n) 1000000
pipe size          (512 bytes, -p) 8
stack size            (kbytes, -s) unlimited
cpu time             (seconds, -t) unlimited
max user processes            (-u) unlimited
virtual memory        (kbytes, -v) unlimited
</ulimit -a>




More information about the Python-list mailing list