Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically add/remove threads to the worker pool in celery

Tags:

python

celery

How do I add more threads (and remove threads) to the current multiprocessing pool, from within a task (i.e. celeryd was run with CELERYD_CONCURRENCY = 10 but I want to change it on-the-fly to CELERYD_CONCURRENCY = 15)?

There is a function called celery.concurrency.processes.TaskPool.Pool.grow but I have no idea how to call that from a running task or whether it is the correct function to do that.

like image 855
Leonth Avatar asked Aug 05 '11 12:08

Leonth


1 Answers

Read the source:

https://github.com/ask/celery/blob/master/celery/concurrency/processes/__init__.py

there's both grow() and shrink(), although the latter seems a tad fishy.

you'd need to keep a reference to the pool somewhere, if you have only one pool, keep it global.

caveat poster: if multiprocessing actually means running multiple separate processes, you might already be in a child process when you try to shrink or grow, and obviously that won't work.

like image 161
Dima Tisnek Avatar answered Nov 15 '22 08:11

Dima Tisnek