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

Ian Kelly ian.g.kelly at
Thu Nov 11 17:30:57 CET 2010

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

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.


More information about the Python-list mailing list