我尝试生成一个进程,该进程开始对我的views.crawl中的某些网站进行爬网,这是ajax响应。但是我收到一个AppRegistryNotReady异常:“提高AppRegistryNotReady(“尚未加载应用程序。”)“。我不知道该怎么解决。
这是我的视图文件:
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)
例外是:
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.