title: Transferring file objects through queue in python
body: <p>I have multiprocessed task that processes input data and writes results into temporary files (for usage later on). However, when I try to transfer the file handles to the parent process through a queue, it fails (no exception is raised, nevertheless the queue remains empty).</p>
  
  <pre><code>import multiprocessing, tempfile
  
  def worker(i):
      my_data_object = []
      my_tmp_file = tempfile.NamedTemporaryFile('wb')
      my_tmp_file.write(bytes('Hello world #{}'.format(i), 'utf-8'))
      my_tmp_file.seek(0)
      queue.put(my_tmp_file)
  
  queue = multiprocessing.Queue()
  
  print('Writing...')
  proc = []
  for i in range(16):
      proc.append(multiprocessing.Process(target = worker, args = (i, )))
      proc[i].start()
  for p in proc:
      p.join()
  
  print('Reading...')
  my_strings = []
  while True:
      try:
          tmp_file = queue.get_nowait()
      except:
          print('All data are read. Queue is now empty')
          break
      my_strings.append(tmp_file.read())
      tmp_file.close()
  
  print('Files content: ', my_strings)
  print('Successful termination')
  </code></pre>
  
  <p>Does anyone know a solution?</p>