Wednesday, November 27, 2013

Re: Trying to run jobs in the background using multiprocessing

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.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment