Creating 50K text files in python

venutaurus539 at gmail.com venutaurus539 at gmail.com
Wed Mar 18 14:40:26 CET 2009


On Mar 18, 6:16 pm, "venutaurus... at gmail.com"
<venutaurus... at gmail.com> wrote:
> Hello all,
>           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.
>
> This is my requiremnt:
>
> C:\TestFolder....
> That folder contains 5 Folders.. Folder1, Folder2, Folder3.....
> Folder5
> Each folder in turn contains 10 folders:
> and Each of those folder contains 1000 text files.
>
> Please let me know if you are not clear.
>
> Thank you,
> Venu Madhav.

-------------
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()
-------------------------------------------------------------------------------------------------------
I can't use a sleep in the main thread because I don't know when the
child threads end.

Thank you,
venu madhav.







More information about the Python-list mailing list