[Fixed]-Apps aren't loaded yet exception occurs when using multi-processing in Django

8👍

This post can solve the problem.

Django upgrading to 1.9 error “AppRegistryNotReady: Apps aren’t loaded yet.”

I had found this answer before, but not actually solve my problems at that time.

After I repeated test, I have to add these codes before import another model,
otherwise, child-process will booting failed and give the error.

import django
django.setup()
from another.app import models

25👍

For others that might stumble upon this in future:

If you encounter this issue while running Python 3.8 and trying to use multiprocessing package, chances are that it is due to the sub processed are ‘spawned’ instead of ‘forked’. This is a change with Python 3.8 on Mac OS where the default process start method is changed from ‘fork’ to ‘spawn’.
This is a known issue with Django.

To get around it:

import multiprocessing as mp
mp.set_start_method('fork')

Leave a comment