title: Multiprocessing Pool is running the whole code for every process created instead of just the function passed to it
body: <p>The python code does a data pull and pre-processing (to convert the data into an iterable for Pool Map to run) and then calls Pool Map to automatically subset the data and run in parallel. However, I find that the data pull and preprocessing are running in each process again in addition to the function that should be running in each process.</p>
  
  <p>Code is as follows: </p>
  
  <pre><code>#Data Pull
  orig_data= pd.read_csv(&lt;fileath&gt;)
  
  #Data Preprocessing
  start=time.time()
  transformed_input=list() # transformed_input is populated with data from orig_data dataframe as required
  end=time.time()
  print("Preprocessing Time")
  print(end-start)
  
  
  def examplefunction(transformed_input_sub):
      # Required Function
      return output
  
  if __name__ == '__main__':
      from multiprocessing import Pool
      p=Pool()
      s=time.time()
      output=p.map(examplefunction,transformed_input)
      p.close()
      p.join()
      e=time.time()
      print("Time Taken")  
      print(e-s)
  </code></pre>
  
  <blockquote>
    <p><strong>Expected Output:</strong><br>
    Preprocessing Time<br>
    5.01<br>
    Time Taken<br>
    10</p>
    
    <p><strong>Actual Output when running on 4 processes:</strong><br>
    Preprocessing Time<br>
    5.01<br>
    Preprocessing Time<br>
    5.12<br>
    Preprocessing Time<br>
    5.35<br>
    Preprocessing Time<br>
    5.41<br>
    Time Taken<br>
    10</p>
  </blockquote>
  
  <p>However, the <strong>output of this code is correct</strong> (and verified) despite the preprocessing running for each process, which is shouldn't be doing as far as I am aware. The problem then arises when instead of a pulling data from a csv containing only a small portion of the data, I use a Teradata Pull for close to 50 million records. The TD pull without multiprocessing works perfectly fine, but with multiprocessing throws the following error:</p>
  
  <blockquote>
    <p>No more spool space in <em>database name</em></p>
  </blockquote>
  
  <p>This is probably each process is running the TD Pull.<br>
  How can I ensure the Pool runs only the function passed to it in parallel and not the complete code from scratch?  </p>
  
  <p>I have tried changing the order of code blocks, calling import statements outside the name == 'main' block, and also put the data pull and preprocessing code in a separate python code and called it using exec() within the main program.</p>