0

I try to spawn a process which starts crawling some website in my views.crawl which is an ajax response. But i get an AppRegistryNotReady exception: "raise AppRegistryNotReady("Apps aren't loaded yet.")". I don't know how to solve it.

This is my views file:

from django.shortcuts import render
from .models import WebPath,FilePath
from django.http import JsonResponse
...
def main(url):
    weburl=WebPath(url,None)
    weburl.save()
    while(WebPath.objects.filter(path=None)):
        starturl()
    downloadfile()

# Create your views here.
def start(request):
    return render(request,'start.html')

@csrf_exempt
def crawl(request):
    global process
    if request.POST['status']=='ok':
        process=multiprocessing.Process(target=main,args=[request.POST['url']])
        process.start()
        print(process.pid)
        return JsonResponse(['ok'],safe=False)
    else:
        process.terminate()
        return JsonResponse(['ok'],safe=False)

the Exception is:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "F:\Anaconda\Anaconda\lib\multiprocessing\spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "F:\Anaconda\Anaconda\lib\multiprocessing\spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
  File "E:\python\django\crawltsinghua\crawl\views.py", line 2, in <module>
    from .models import WebPath,FilePath
  File "E:\python\django\crawltsinghua\crawl\models.py", line 4, in <module>
    class WebPath(models.Model):
  File "F:\Anaconda\Anaconda\lib\site-packages\django\db\models\base.py", line 87, in __new__
    app_config = apps.get_containing_app_config(module)
  File "F:\Anaconda\Anaconda\lib\site-packages\django\apps\registry.py", line 249, in get_containing_app_config
    self.check_apps_ready()
  File "F:\Anaconda\Anaconda\lib\site-packages\django\apps\registry.py", line 132, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Juan Carlos Ramirez
  • 2,054
  • 1
  • 7
  • 22
jameslahm
  • 1
  • 1
  • 4
  • How does your settings.py file look? have you included your app in the INSTALLED_APPS section? – Juan Carlos Ramirez Jun 06 '19 at 15:33
  • @Juan Carlos Ramirez Yes,I included my app in the INSTALLED_APPS section. – jameslahm Jun 06 '19 at 15:42
  • Could you post the code from that section as well? Also check this out, it might help you: https://stackoverflow.com/questions/26276397/django-1-7-upgrade-error-appregistrynotready-apps-arent-loaded-yet – Juan Carlos Ramirez Jun 06 '19 at 15:45
  • @Juan Carlos Ramirez Thx , but I check that out which can't fix my problem. This is the INSTALLED_APPS: `INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'crawl', ]` – jameslahm Jun 07 '19 at 01:52
  • And 'crawl' is my app. – jameslahm Jun 07 '19 at 01:53

0 Answers0