title: Using python multiprocess outside the main script
body: <p>According to the <a href="https://docs.python.org/2/library/multiprocessing.html#multiprocessing-programming" rel="noreferrer">docs</a> of python's multiprocess the spawning of process needs to be inside of the <code>if __name__ == '__main__':</code> clause to prevent spawning infinite processes.</p>
  
  <p>My question, is it possible to use multiprocess inside of an import?</p>
  
  <p>Something along those lines of this:
  let's say I have this py which is the main executed file:</p>
  
  <pre><code>import foo
  
  def main():
      foo.run_multiprocess()
  
  if __name__ =='__main__':
      main()
  </code></pre>
  
  <p>and the foo.py file which is imported:</p>
  
  <pre><code>def run_multiprocess(number_to_check):
      if number_to_check == 5:
          print(number_to_check)
  
  if __name__ == '__main__':
      list_to_check = {1,2,3,4,5,6,7}
      pool = Pool(processes=4)             
      pool.map(process_image, list_to_check) 
  </code></pre>
  
  <p>Obviusly this won't work because the code inside the if statment in foo.py won't run. Is there a way to make it work though?</p>