Open Multiples Files at same time with multiprocessing - How "declare" dynamically the var?

Ian Kelly ian.g.kelly at gmail.com
Thu Nov 11 11:30:57 EST 2010


On 11/11/2010 4:28 AM, macm wrote:
>      def openFiles(self,file,q):
>          fp = open(file, 'rb')
>          fp.seek(0)

The seek is unnecessary; the file will already be at position 0 after it 
is opened.

>      def testOpen(self):
>          L =
> ['file1.txt','file2.txt','file3.txt','file4.txt','file5.txt']
>          d1 = []
>          for x in L:
>              z=L.index(x)

"for z, x in enumerate(L):"

>              q = Queue()
>              m = Process(target=self.openFiles, args=(x,q,))
>              m.start()
>              d1.append(q.get()) #<= This get is locking ? It is mean:
> "wait m.start(), like m.join()??"

It can't get an item from the queue until an item has been put in the 
queue to get, so it waits for the process m to put something there.  It 
does not do an implicit m.join() however.

> I tried use list but didn't work look below one shot.

"It didn't work" is not very useful for helping you debug.  Be specific. 
  What were you expecting, and what did you get instead?  If there was a 
traceback, copy and paste it.

Cheers,
Ian




More information about the Python-list mailing list