I've found a great example on how to do threads. It compares a ping program in regular for loop and with threaded for loop. The link is below if anyone is interested.<br><br><a href="http://www.wellho.net/solutions/python-python-threads-a-first-example.html">http://www.wellho.net/solutions/python-python-threads-a-first-example.html</a><br>
<br>I hope my eagerness to post doesn't annoy anyone. I like to get as much info from as many places as possible and compare. This way I think I may have a better solution for a problem. Plus people that Google will find this post or any words in it. Any more information on threading a for loop would be greatly appreciated. TIA<br>
<br clear="all">-Alex Goretoy<br><a href="http://www.alexgoretoy.com">http://www.alexgoretoy.com</a><br><br>
<br><br><div class="gmail_quote">On Mon, Jan 5, 2009 at 6:00 AM, alex goretoy <span dir="ltr"><<a href="mailto:aleksandr.goretoy@gmail.com">aleksandr.goretoy@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello All,<br><br>I have a question. I'm not sure exactly as how to explain it in any other way then the way I will explain it. So I'm sorry if it's hard to understand exactly what it is I'm trying to do. Maybe not. Anyway. Here goes.<br>

<br>Lets say I have a file that looks like this.<br><br>id,name,desc,test<br>123,abc,testing is fun,yeah baby<br>456,qwe,python makes if funner, yeah baby<br>789,zxc,this is another line in this file, yeah baby<br>...<br>

...<br><br>This file can have an unknown amount of lines in it. It can be 700,400 or even 7,000.<br>I do this to read the file:<br><br>        try:<br>            reader = csv.reader(file(filename, "rb"))<br>            try:<br>

                header = reader.next()<br>                self.buffer = list(reader) # total = len(self.buffer)<br>                self.bufferp= [dict(zip(header,line)) for line in self.buffer]<br>                self.header = header<br>

                #for row in reader:<br>                    #self.buffer.append(row)<br>                    #s,a=[],{}<br>                    <br>                    #for j in range(len(self.buffer[0])):<br>                        #a[self.buffer[0][j]]=row[j]<br>

                    #self.bufferp.append(a)<br>                    #i+=1<br>                #self.total = i-1<br>            except csv.Error, e:<br>                sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))<br>

        except IOError, e:<br>            sys.exit('file %s, IOError: %s' % (filename, e))<br><br>What I am currently doing is looping over this file, performing a function for every line. This function isbeing called from this class __init__(), <br>

<br>def loop_lines(self):<br>        <br>        for k in range(len(self.buffer)): #for every line in csv file<br>            self.line=self.buffer[k]<br>            self.some_function(self.line)<br>            <br>            <br>

Now, for my question. Is it possible for me to thread this scenario somehow?<br><br>So that I can set a variable that says how many lines to work on at the same time?<br><br>lets say 10 lines at a time, once it finishes some it moves on to the next ones that are not in the thread pool or something to that nature. Always making sure that it works on 10 at the same time.<br>

<br>How would I achieve something like this in my program? Can someone please recommend something for me. I would greatly appreciate. My program would appreciate it too, seeing as it will be multi-threaded :) Thank you for your help.<br>
<font color="#888888">
<br clear="all">-Alex Goretoy<br><a href="http://www.alexgoretoy.com" target="_blank">http://www.alexgoretoy.com</a><br><br>
</font></blockquote></div><br>