title: Using multiprocessing in python script with Django models
body: <p>I am writing a custom script to run multiple instances of the same functions using multiprocessing with django models.</p>
  
  <p>The code which concerns this post consists of:</p>
  
  <pre><code>if __name__ == '__main__':
      for count, script in enumerate(scripts):
          for counter in range(0, len(counters)):
              p = Process(target=script, args=(counters[counter][count],))
              p.start()
              p.join()
  </code></pre>
  
  <p>the loops execute correctly, but I am having a problem with the <code>__name__ == '__main__'</code> statement. I could hack it together to say <code>__name__=__main__</code> before that line, but then I would run into a problem where <code>p.start()</code> throws an error for:</p>
  
  <pre><code>PicklingError: Can't pickle &lt;function nordstrom_script at 0x0000000003B2A208&gt;: it's not            found as __main__.nordstrom_script
  </code></pre>
  
  <p>I am relatively new to python/django and have never experimented with multiprocessing before, so please excuse my lack of knowledge if something is dreadfully wrong with my logic. </p>
  
  <p>Any help resolving this would be greatly appreciated. I know that django does not work well with multiprocessing, and the problem comes from me using:</p>
  
  <pre><code>&gt;&gt;&gt;python manage.py shell
  &gt;&gt;&gt;execscript('scripts/script.py')
  </code></pre>
  
  <p>and not</p>
  
  <pre><code>&gt;&gt;&gt;python scripts/script.py
  </code></pre>