Maximum number of threads

Kirby Angell kangell at alertra.com
Wed Sep 29 11:26:43 EDT 2004


Michael Fuhr wrote:
> What happens when you hit this "hard limit"?  If there's an error
> message then it might hint at the problem.

If I run this program:

import thread, time

def t(parm1,parm2):
	time.sleep( 1000 )

tc = 0
try:
	while 1:
		thread.start_new_thread( t, (None,None) )
		tc += 1
		time.sleep( 0.05 )
finally:
	print tc


This is the result:
$ python t.py
404
Traceback (most recent call last):
   File "t.py", line 12, in ?
     thread.start_new_thread( t, (None,None) )
thread.error: can't start new thread

> I'm not current on Linux threading models -- do these versions of
> Linux create a new process for each thread?  If so, could resource
> limits be preventing you from creating more threads?

I don't think Linux creates a new process for each thread.  Sure seems 
like this would have to be something related to python since 2.2 could 
create a thousand or more threads.  Although I have to admit that it is 
odd that the maximum number of threads I can create on RH9 is different 
than on FC2.



More information about the Python-list mailing list