Monday, January 2, 2012

Re: technique about using thread in views.py

Don't use Thread, use Celery [1] and django-celery[2].

You will also need one of several available brokers, like RabbitMQ[3][6], or kombu[4] + django-kombu[5].


Happy reading!

Cheers,
AT

[1] http://ask.github.com/celery/
[2] http://pypi.python.org/pypi/django-celery/
[3] http://www.rabbitmq.com/
[4] http://pypi.python.org/pypi/kombu/
[5] https://github.com/ask/django-kombu
[6] http://webcookies.org/blog/2009/09/10/rabbitmq-celery-and-django/


On Mon, Jan 2, 2012 at 8:37 AM, Kay <fcapba1220@gmail.com> wrote:
Hi,guys~
Happy new year ^^
I am a beginner at django.
I want to run a very simple thread in django project.
when view.py after running welcome_page.html to show a html on browser
then call a thread print something on background.
But I can't run it well with those two merged in views.py.
Following is the code I used.
What's wrong with my code....
Any tips?
Thanks.

Kay
-----------------------------------------------------------------------------------
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.core.context_processors import csrf
from threading import Thread

def welcome(request):
   c = {}
   c.update(csrf(request))
   return render_to_response("welcome_page.html",c)

   go = test()
   go.start()

class test(Thread):

       def __init__(self):
               Thread.__init__(self)

       def run(self):
               print 'thread is running'

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment