title: mpi4py TypeError: cannot serialize '_io.TextIOWrapper' object
body: <p>I was running the following code to test the broadcasting files using mpi_bcast. Basically, I created a text file "test.txt" at the root and broadcast to the other nodes.</p>
  
  <pre><code>import json
  import numpy as np
  import multiprocessing
  import time
  import sys
  import os
  import math
  from scipy.special import comb
  import itertools
  from mpi4py import MPI
  
  comm = MPI.COMM_WORLD
  size = comm.Get_size()
  rank = comm.Get_rank()
  
  if rank == 0:
      with open('test.txt', 'w') as f:
          for x in range(50):
              f.write('{}\n'.format(x))
      data = open('test.txt', 'r')
      print(rank)
  else:
      data = None
  
  data = comm.bcast(data, root=0)
  
  if rank != 0:
      f_out = open('test.txt', 'w')
      for i, line in enumerate(data):
          f_out.write(line)
      f_out.close()
  
  print('rank',rank)
  </code></pre>
  
  <p>Then when I run mpiexec -n 3 python3 test.py over 3 processes, I get teh following error messages.</p>
  
  <p>Traceback (most recent call last):</p>
  
  <pre><code>File "test.py", line 26, in &lt;module&gt;
      data = comm.bcast(data, root=0)
    File "mpi4py/MPI/Comm.pyx", line 1257, in mpi4py.MPI.Comm.bcast
    File "mpi4py/MPI/msgpickle.pxi", line 629, in mpi4py.MPI.PyMPI_bcast
    File "mpi4py/MPI/msgpickle.pxi", line 104, in mpi4py.MPI.Pickle.dump
    File "mpi4py/MPI/msgpickle.pxi", line 91, in mpi4py.MPI.Pickle.cdumps
  TypeError: cannot serialize '_io.TextIOWrapper' object
  </code></pre>
  
  <p>I think the error happens at this line: <code>data = comm.bcast(data, root=0)</code>.</p>
  
  <p>Is it because I cannot pass a file object to the bcast function? How can I fix this error?</p>