Wednesday, November 27, 2013

Re: Trying to run jobs in the background using multiprocessing

Hi again,

Thanks for all your answers.
Yes, I also found out many recommend Celery, but I was hoping for a "simpler" solution, if there is one...
Doug, I already tried without the self in arguments, but got the same error, unfortunately.

I guess if there isn't another simpler way, I'll have to dig into Celery.

Cheers,
Pau

On Thursday, November 28, 2013 4:01:25 AM UTC+1, Doug Blank wrote:
On Wed, Nov 27, 2013 at 2:58 PM, Pau Creixell <paucr...@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))

I suspect that if you are setting the target to be self.Run, then the
args should not include self:

Thread = multiprocessing.Process(target = self.Run,
args=(ReferenceSeparator, MutationSeparator))

-Doug

>            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...@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/27f043ea-d59d-42ee-9529-0bf86ade31b0%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

--
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/5f2c1e2d-2833-4d81-8fda-bbf11a473fae%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment