title: Multiprocessing with Django - fork causes random deadlocks
body: <p>I've tried to start Django multiprocess pool with <code>fork</code> context, but without any-apparent-reason, sometimes, the main application (that control the pool) freezes, without doing anything else.</p>
  <p>This is how I start my pool:</p>
  <pre><code>model_instances = [instance1, instance2, instance3, instancen]
  with multiprocessing.get_context('fork').Pool(multiprocessing.cpu_count()) as pool:
      pool.map(_run_par_task, model_instances)
  </code></pre>
  <p>After looking at this <a href="https://pythonspeed.com/articles/python-multiprocessing/" rel="nofollow noreferrer">page</a>, I've seen that it describes my issue, and I suspect that sometimes, the fork method causes some deadlocks.</p>
  <p>So, i've tried to use the <code>spawn</code> method to manage my pool, as following:</p>
  <pre><code>model_instances = [instance1, instance2, instance3, instancen]
  with multiprocessing.get_context('spawn').Pool(multiprocessing.cpu_count()) as pool:
      pool.map(_run_par_task, model_instances)
  </code></pre>
  <p>...but i'm getting this error message:</p>
  <pre><code>django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
  </code></pre>
  <p>That clearly indicates that Django apps are not loaded in the child process.</p>
  <p>Basically, I need to work in the child process with Django models, so, how I can load the Django app in the child spawned processes?</p>