Wednesday, November 27, 2013

Re: Trying to run jobs in the background using multiprocessing

maybe your webserver won't permit multiprocessing, it depends on how you are running django.

In any case I would also recommend celery, in this case you have control on how many workers are running, having a webrequest open yet another process means you won't have control on how many processes are running, easily taking your server down.

with celery you just add a task to the queue, and you can have that on a different server if you would like

success
avraham


On Wed, Nov 27, 2013 at 10:11 PM, Timothy W. Cook <tim@mlhim.org> wrote:
When I asked about this it seems that the best solution is to use
Celery in combination with Django.  There seems to be quite a bit of
good experience here using them together.

HTH,
Tim


On Wed, Nov 27, 2013 at 5:58 PM, Pau Creixell <paucreixell@gmail.com> wrote:
> Hi there!
>
> I am trying to run jobs in the background using the following (minimal)
> code:
>
> Under views.py:
>
> def submit(request):
>    model = MyModel()
>    model.RunInAThread(ReferenceSeparator, MutationSeparator)
>
> Under models.py:
>
> class MyModel(models.Model):
>    def RunInAThread(self, ReferenceSeparator, MutationSeparator):
>            print 1
>            Thread = multiprocessing.Process(target = self.Run, args=(self,
> ReferenceSeparator, MutationSeparator))
>            print 2
>            Thread.daemon = True
>            print 3
>            Thread.start()
>            print 4
>
>    def Run(self, ReferenceSeparator, MutationSeparator):
>            print 5
>
>
> But I get the error below and it only print 1, 2, 3 and 4, but not 5:
>
> TypeError at /submit
> 'str' object is not callable
> ...
> Exception Location: /sw/lib/python2.6/multiprocessing/forking.py in
> __init__, line 98
> ...
>
> I have tried in many different ways (e.g. Daemon = False, without "self" as
> an "args"), but don't really understand why this would not work, unless
> Django doesn't permit multiprocessing (which some people seem to suggest
> online).
> Any help will be highly appreciated.
>
> Best wishes,
> Pau
>
> --
> 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+unsubscribe@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/27f043ea-d59d-42ee-9529-0bf86ade31b0%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
MLHIM VIP Signup: http://goo.gl/22B0U
============================================
Timothy Cook, MSc           +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

--
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+unsubscribe@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/CA%2B%3DOU3W-SM3-tUq2-hhAh6zoAbAr_HuYCrq6gHwHdkHyj4Go0Q%40mail.gmail.com.

--
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+unsubscribe@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/CAFWa6t%2BJZufMPXQhR0pkRYifpco%2BjsQu9%3DqbBMG7rrbrkpPzTQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment