Hi Vijay Khemlani

I tried tutorial. and "error: timed out" was disappeared!

http://celery.readthedocs.org/en/latest/django/first-steps-with-django.html
was deprecated.

http://docs.celeryproject.org/en/master/django/first-steps-with-django.html
is new.

I added the code in my app/__init__.py:

---
from __future__ import absolute_import

# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
---

How do I call other process?

Is it okey?

@shared_task
def my_task():
    cmd = "cd program_path;python my_program.py"
    import subprocess
    proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, 
stderr=subprocess.STDOUT)
    return proc


I call my my_task function in the view

---
def run_celery(request):
    result = my_task.delay()
    while not result.ready():
        print 'processing...'
    print result.get()

    return HttpResponse("test")


2015年1月9日金曜日 13時49分15秒 UTC+9 Sugita Shinsuke:
>
> Hi Vijay Khemlani
>
> Thank you for replying. 
>
> >Have you done the celery tutorial?
> I have not done the celery tutorial yet.
>
> But, I ran Redis and set below in my settings.py
>
> BROKER_URL = 'redis://localhost'
> CELERY_RESULT_BACKEND = 'redis'
> CELERY_TASK_SERIALIZER = 'json'
> CELERY_RESULT_SERIALIZER = 'json'
> CELERY_ACCEPT_CONTENT = ['json']
>
> I also ran celery command.
>
> celery -A app_name worker -l info 
>
>
> Is it the tutorial URL you said?
>
> http://celery.readthedocs.org/en/latest/django/first-steps-with-django.html
>
> Thank you.
>
> 2015年1月9日金曜日 13時24分25秒 UTC+9 Vijay Khemlani:
>>
>> Have you done the celery tutorial?
>>
>> Async tasks require you to have a broker (rabbitmq or something) and also 
>> to create some workers that actually execute the task.
>>
>> On Fri, Jan 9, 2015 at 12:55 AM, Sugita Shinsuke <shin...@gmail.com> 
>> wrote:
>>
>>> Hi somecallitblues 
>>>
>>> Thank you for replying.
>>> I installed Celery 3.1.17.
>>>
>>> And, I setup 
>>>
>>> I created add method in tasks.py
>>>
>>> my tasks.py
>>> ----
>>> from __future__ import absolute_import
>>>
>>> from celery import shared_task
>>>
>>>
>>> @shared_task
>>> def add(x, y):
>>>     return x + y
>>> ----
>>>
>>> I also called my add method from my view.
>>>
>>> hoge_view.py
>>> ---
>>> def run_celery(request):
>>>     result = add.delay(3, 8)
>>>     while not result.ready():
>>>         print 'spam'
>>>     print result.get()
>>>     return HttpResponse("test")
>>> ---
>>>
>>> I called it from url.
>>>
>>> "error: timed out" was occurred.
>>>
>>> Why is it timed out? Could you help me?
>>>
>>>
>>> 2015年1月8日木曜日 19時19分20秒 UTC+9 somecallitblues:
>>>>
>>>> Look into celery. It's the best and easiest way to run bg jobs imo
>>>> On 08/01/2015 9:10 pm, "Sugita Shinsuke" <shin...@gmail.com> wrote:
>>>>
>>>>> Hi there.
>>>>>
>>>>> I'd like to run background application.
>>>>>
>>>>> I coded this code.
>>>>>
>>>>> I wrote the urls.py and I added in the view.
>>>>>
>>>>> def run_junix(request):
>>>>>     cmd = "cd app_path;nohup python background_app.py &"
>>>>>     import subprocess
>>>>>     proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, 
>>>>> stderr=subprocess.STDOUT)
>>>>>
>>>>>     return HttpResponse("bg test")
>>>>>
>>>>> Is it good way? or using supervisor or, if you know the better way, 
>>>>> would you tell me?
>>>>>
>>>>> Anyone who know this matter, please help.
>>>>>
>>>>>  -- 
>>>>> You received this message because you are subscribed to the Google 
>>>>> Groups "Django users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>> an email to django-users...@googlegroups.com.
>>>>> To post to this group, send email to django...@googlegroups.com.
>>>>> Visit this group at http://groups.google.com/group/django-users.
>>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>>> msgid/django-users/0a8222ff-a22c-44a5-a098-2b663aaca294%
>>>>> 40googlegroups.com 
>>>>> <https://groups.google.com/d/msgid/django-users/0a8222ff-a22c-44a5-a098-2b663aaca294%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/b5e2226c-9825-4409-bc91-4b97f5c0609e%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/b5e2226c-9825-4409-bc91-4b97f5c0609e%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c2628291-3c30-4f7c-9d94-b565a066fb93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to