[Tutor] Breaking threads

kromag@nsacom.net kromag@nsacom.net
Mon, 30 Apr 2001 16:06:53 -0700 (PDT)


Howdy,

I am working my way through "Programming Python" from the begining (I have 
asked too many silly questions! :-). Here is a non-silly question:

When I run the following:

----------begin stuff------------------------------

import thread, time 

glarf=open('\windows\desktop\goat.txt', 'w')

def counter(myId, count):
    for i in range(count):
	mutex.acquire()
#	time.sleep(1)
	glarf.write('[%s]=> %s' % (myId, i))
	mutex.release()
		
mutex = thread.allocate_lock()
for i in range(10000):
	thread.start_new_thread(counter, (i, 3))
	
time.sleep(6)
print "Your greasy granny's got holes in her panties. And your main thread is 
exiting...."

--------end stuff---------------

It starts to write 10,000 counts to goat.txt, then dies with the following:


Traceback (most recent call last):
  File "cornfedbeef.py", line 14, in ?
    thread.start_new_thread(counter, (i, 3))
thread.error: can't start new thread

It works fine in iterations of 10, 100 and 1000. Why does it puke at the 
10000 mark?


Wow!

d