title: Why doesn't `print` work in Python multiprocessing pool.map
body: <p>I am trying to implement the <code>multiprocessing</code> module for a working with a large csv file. I am using Python 2.7 and following the example from <a href="https://stackoverflow.com/questions/8717179/chunking-data-from-a-large-file-for-multiprocessing">here</a>.</p>
  
  <p>I ran the unmodified code (copied below for convenience) and noticed that <code>print</code> statements within the <code>worker</code> function do not work. The inability to <code>print</code> makes it difficult to understand the flow and debug.</p>
  
  <p>Can anyone please explain why <code>print</code> is not working here? Does pool.map not execute print commands? I searched online but did not find any documentation that would indicate this.</p>
  
  <pre><code>import multiprocessing as mp
  import itertools
  import time
  import csv
  
  def worker(chunk):
      # `chunk` will be a list of CSV rows all with the same name column
      # replace this with your real computation
      print(chunk)     # &lt;----- nothing prints
      print 'working'  # &lt;----- nothing prints
      return len(chunk)  
  
  def keyfunc(row):
      # `row` is one row of the CSV file.
      # replace this with the name column.
      return row[0]
  
  def main():
      pool = mp.Pool()
      largefile = 'test.dat'
      num_chunks = 10
      results = []
      with open(largefile) as f:
          reader = csv.reader(f)
          chunks = itertools.groupby(reader, keyfunc)
          while True:
              # make a list of num_chunks chunks
              groups = [list(chunk) for key, chunk in
                        itertools.islice(chunks, num_chunks)]
              if groups:
                  result = pool.map(worker, groups)
                  results.extend(result)
              else:
                  break
      pool.close()
      pool.join()
      print(results)
  
  if __name__ == '__main__':
      main()
  </code></pre>