En Wed, 18 Mar 2009 11:40:26 -0200, venutaurus...@gmail.com <venutaurus...@gmail.com> escribió:
On Mar 18, 6:16 pm, "venutaurus...@gmail.com"
<venutaurus...@gmail.com> wrote:

          I've an application where I need to create 50K files spread
uniformly across 50 folders in python. The content can be the name of
file itself repeated 10 times.I wrote a code using normal for loops
but it is taking hours together for that. Can some one please share
the code for it using Multithreading. As am new to Python, I know
little about threading concepts.

I managed to get this code but the problem is main thread exits before
the completetion of child threads:

class MyThread ( threading.Thread ):

   def run ( self ):

      global theVar
      print 'This is thread ' + str ( theVar ) + ' speaking.'
      print 'Hello and good bye.'
      theVar = theVar + 1
      time.sleep (4)
      print 'This is thread ' + str ( theVar ) + ' speaking. again'

for x in xrange ( 20 ):
   MyThread().start()

You have to .join() each thread. Replace the above two lines with:

threads = [MyThread() for x in range(20)]
for thread in threads:
  thread.start()
for thread in threads:
  thread.join()

But this is unrelated to your main problem. You don't have to use threads for this.

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to