Dynamically add/remove threads to the worker pool in celery

拥有回忆 提交于 2020-01-03 09:04:48

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/6956272/dynamically-add-remove-threads-to-the-worker-pool-in-celery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!