thread stomp?

Jerry Hill malaclypse2 at gmail.com
Mon May 12 16:33:05 EDT 2008


On Mon, May 12, 2008 at 4:00 PM, pyn3wb <pyn3wb at pyn3wb.com> wrote:
>  class main

Why are you making main a class?  It should almost certainly be a
function (defined with "def", not "class").

>         for i in dircache.listdir(dir):
>                 //run over files
>                 class1(dir).start()

You've started a bunch of threads.  If you want to wait for them to
all finish, you need to call .join() on them all.  You can't do that
unless you save references to your threads, like this:

threads = []
for i in dircache.listdir(dir):
    new_thread = class1(dir)
    new_thread.start()
    threads.append(new_thread)

for thread in threads:
    thread.join()

Beyond that, the code you've posted is not correct.  You've left off a
required ":"  in your definition of class main, and your comments are
not valid python comments.  Your for loops don't make a whole lot of
sense to me either.  Are they supposed to be iterating across files in
a directory?  If so, why do you start up all of your threads with
"dir" instead of "i" or "j" as the parameter to your new thread?

-- 
Jerry



More information about the Python-list mailing list