2017-10-29 1 views
1

Hallo Ich möchte Sellerie Aufgaben in meinem Django-Projekt verwenden und ich versuche, diese sehr gute tutorial von Mr.Vitor Freitas zu folgen.django Sellerie Verzögerung Funktion nicht exetute

aber in meinem Fall und wenn versuchen, es zu tun Tutorial project Ich bekomme keine Ergebnisse zurück die Funktionen nicht ausführen und in meinem Fall und im Tutorial (ich nehme Nachricht zu warten und zu aktualisieren und nichts nach der Aktualisierung) .

Irgendeine Idee warum?

Ich denke, das Problem ist vielleicht in RABBITQM Server? Einige Konfiguration?

Installieren Sie einfach Erlang (otp_win64_20.1.exe) und nach RabbitMQ (rabbitmq-server-3.6.12.exe)

hier Beispielcode:

settings.py

CELERY_BROKER_URL = 'amqp://localhost' 

celery.py

from __future__ import absolute_import 
import os 
from celery import Celery 

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 

app = Celery('mysite') 
app.config_from_object('django.conf:settings', namespace='CELERY') 
app.autodiscover_tasks() 

Aufgaben. py

import string 

from django.contrib.auth.models import User 
from django.utils.crypto import get_random_string 

from celery import shared_task 


@shared_task 
def create_random_user_accounts(total): 
    for i in range(total): 
     username = 'user_{}'.format(get_random_string(10, string.ascii_letters)) 
     email = '{}@example.com'.format(username) 
     password = get_random_string(50) 
     User.objects.create_user(username=username, email=email, password=password) 
    return '{} random users created with success!'.format(total) 

_ _init_ _.py 

from .celery import app as celery_app 

__all__ = ['celery_app'] 

views.py

from django.contrib.auth.models import User 
from django.contrib import messages 
from django.views.generic import TemplateView 
from django.views.generic.list import ListView 
from django.views.generic.edit import FormView 
from django.shortcuts import redirect 

from .forms import GenerateRandomUserForm 
from .tasks import create_random_user_accounts 


class UsersListView(ListView): 
    template_name = 'core/users_list.html' 
    model = User 


class GenerateRandomUserView(FormView): 
    template_name = 'core/generate_random_users.html' 
    form_class = GenerateRandomUserForm 

    def form_valid(self, form): 
     total = form.cleaned_data.get('total') 
     create_random_user_accounts.delay(total) 
     messages.success(self.request, 'We are generating your random users! Wait a moment and refresh this page.') 
     return redirect('users_list') 

hier Details nach cd mein Projektpfad>celery -A mysite worker -l info:

C:\Windows\System32>cd C:\Users\username\Desktop\django-celery-example-master 

C:\Users\username\Desktop\django-celery-example-master>celery -A mysite worker -l info 

-------------- [email protected] name v4.1.0 (latentcall) 
---- **** ----- 
--- * *** * -- Windows-8-6.2.9200 2017-10-29 18:10:24 
-- * - **** --- 
- ** ---------- [config] 
- ** ---------- .> app:   mysite:0x404e5c0 
- ** ---------- .> transport: amqp://guest:**@localhost:5672// 
- ** ---------- .> results:  disabled:// 
- *** --- * --- .> concurrency: 4 (prefork) 
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker) 
--- ***** ----- 
-------------- [queues] 
       .> celery   exchange=celery(direct) key=celery 


[tasks] 
    . mysite.core.tasks.create_random_user_accounts 

[2017-10-29 18:10:24,596: CRITICAL/MainProcess] Unrecoverable error: TypeError('must be integer<K>, not _subprocess_handle',) 
Traceback (most recent call last): 
    File "C:\Python27\lib\site-packages\celery\worker\worker.py", line 203, in start 
    self.blueprint.start(self) 
    File "C:\Python27\lib\site-packages\celery\bootsteps.py", line 119, in start 
    step.start(parent) 
    File "C:\Python27\lib\site-packages\celery\bootsteps.py", line 370, in start 
    return self.obj.start() 
    File "C:\Python27\lib\site-packages\celery\concurrency\base.py", line 131, in start 
    self.on_start() 
    File "C:\Python27\lib\site-packages\celery\concurrency\prefork.py", line 112, in on_start 
    **self.options) 
    File "C:\Python27\lib\site-packages\billiard\pool.py", line 1007, in __init__ 
    self._create_worker_process(i) 
    File "C:\Python27\lib\site-packages\billiard\pool.py", line 1116, in _create_worker_process 
    w.start() 
    File "C:\Python27\lib\site-packages\billiard\process.py", line 124, in start 
    self._popen = self._Popen(self) 
    File "C:\Python27\lib\site-packages\billiard\context.py", line 383, in _Popen 
    return Popen(process_obj) 
    File "C:\Python27\lib\site-packages\billiard\popen_spawn_win32.py", line 64, in __init__ 
    _winapi.CloseHandle(ht) 
TypeError: must be integer<K>, not _subprocess_handle 
Traceback (most recent call last): 
    File "<string>", line 1, in <module> 
    File "C:\Python27\lib\site-packages\billiard\spawn.py", line 159, in spawn_main 
    new_handle = steal_handle(parent_pid, pipe_handle) 
    File "C:\Python27\lib\site-packages\billiard\reduction.py", line 126, in steal_handle 
    _winapi.DUPLICATE_SAME_ACCESS | _winapi.DUPLICATE_CLOSE_SOURCE) 
WindowsError: [Error 6] 

Antwort

1

Celery 4.x does not support Windows, und in meiner Erfahrung ist es die Prefork/Billard Teile, die kaputt gehen. Die Arbeit mit dem Arbeiter mit --pool solo sollte funktionieren.

+0

Wie mache ich das? Ich brauche andere Sellerie-Version? – Mar

+1

Sie können 'pip install sellery == 3.1.25' verwenden. – hybor

Verwandte Themen