Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to create multiple threads and by using a for loop. I want the threads to then run another part of my script using the iteration number of the loop as a variable. The result of each thread should create a log file which is already defined in my script. For some reason though not all log files are created and not all the tests aren't run:

import thread
import os

def test(x, name):
....

try:
for ip in range(int(start), (int(end) + 1)):
    threadname = str(ip)
    thread.start_new_thread(test, (ip, threadname, ))
except:
    print "Error"

while 1:
    pass

I know there is another module called Threading which can be used to make threads but do you think this may be the reason not all my threads are being started? Or is it something else completely?

share|improve this question
    
Is there any exception thrown and "Error" printed? If so, it would be useful to import sys and print sys.exc_info() in except: block. –  ElmoVanKielmo Jul 1 '13 at 15:37
    
Apart from a missing indent (after the try:) I cannot see obvious errors: all your threads should start. Your code is incomplete so it's hard to understand what your problem is. My suggestion: avoid thread and use threading, it's much more user friendly, and gives you much more control. –  Stefano M Jul 1 '13 at 15:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.