Re: Re: Way to restart workers after certain tasks?
So… I coded this up today and it seems to work nicely. I wanted to make sure this is acceptable though..
there isn't cleanup that ought to get done by Celery for these workers in cases like this? When I see these
lines on a graceful Celery shutdown it gives me pause about throwing SystemExit from the signal…
[2011-08-02 18:08:52,771: DEBUG/MainProcess] joining pool workers
[2011-08-02 18:08:52,771: DEBUG/MainProcess] pool workers joined
[2011-08-02 18:08:52,772: DEBUG/MainProcess] running the remaining "atexit" finalizers
Phill
On Aug 2, 2011, at 5:32 AM, Miguel Hernández wrote:
> Hi Phill,
>
> You can also use signals to raise an exception that kills the worker
> just after executing the task. If an exception raises in a signal
> handler it will not affect the status of the task.
>
> from celery.signals import task_postrun
> from celery.task import task
>
> <at> task
> def do_something():
> return "whatever"
>
> def shutdown_worker(**kwargs):
> raise SystemExit()
>
> task_postrun.connect(shutdown_worker, sender=do_something)
>
> bye
>
> On Tue, Aug 2, 2011 at 12:39 PM, Mher Movsisyan
> <mher.movsisyan@...> wrote:
>> Phill,
>>
>> In that case you can create a special worker with CELERYD_MAX_TASKS_PER_CHILD and route your "special"
tasks to that worker. Remaining tasks will go to other workers with no task-per-child limitations.
>>
>> Mher
>>
>>
>> On Aug 2, 2011, at 8:22 AM, phill wrote:
>>
>>> Mher,
>>>
>>> Thanks.. I did see that option, but it doesn't solve the problem I
>>> have very elegantly. The problem I have is that I've got a couple of
>>> tasks that eat up loads of memory. Basically, any worker that runs one
>>> of these tasks ought to be shut down afterward... These tasks run
>>> rarely, so it shouldn't be a huge deal. I don't want to set my max-
>>> tasks to 1 though, which is what I would need to do to accomplish
>>> that. Make sense?
>>>
>>> Phill
>>>
>>> On Jul 29, 11:04 pm, Mher Movsisyan <mher.movsis...@...> wrote:
>>>> On Jul 30, 2011, at 12:49 AM, Phill wrote:
>>>>
>>>>> Wacky question.. I've got a couple really big memory/cpu tasks that appear to
>>>>> be leaking (I'm rebuilding some haystack indexes nightly).. I'm not sure
>>>>> why the memory isn't being recovered yet (since it seems to work nicely in my
>>>>> local environment).... but until I get it figured out, I'm wanting to make
>>>>> sure the process that ran the task doesn't stick around.
>>>>
>>>>> Of course I can hook up a cron job that runs the task in a management command
>>>>> independently, but I figured I'd ask if there was a way to do this in through
>>>>> celery/celerybeat instead... just in case there was a neat way to do this.
>>>>
>>>> CELERYD_MAX_TASKS_PER_CHILD option sets the number of tasks a worker process executes before
it’s replaced by a new process.
>>>>
>>>> http://ask.github.com/celery/userguide/workers.html#max-tasks-per-chi...
>>>>
>>>> Mher
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups "celery-users" group.
>>> To post to this group, send email to celery-users@...
>>> To unsubscribe from this group, send email to celery-users+unsubscribe <at> googlegroups.com.
>>> For more options, visit this group at http://groups.google.com/group/celery-users?hl=en.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups "celery-users" group.
>> To post to this group, send email to celery-users@...
>> To unsubscribe from this group, send email to celery-users+unsubscribe <at> googlegroups.com.
>> For more options, visit this group at http://groups.google.com/group/celery-users?hl=en.
>>
>>
>
>
>
> --
> Obstáculos es lo que ves cuando apartas la vista del objetivo.
>
> --
> You received this message because you are subscribed to the Google Groups "celery-users" group.
> To post to this group, send email to celery-users@...
> To unsubscribe from this group, send email to celery-users+unsubscribe <at> googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/celery-users?hl=en.
>
--
--
You received this message because you are subscribed to the Google Groups "celery-users" group.
To post to this group, send email to celery-users@...
To unsubscribe from this group, send email to celery-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/celery-users?hl=en.