简体   繁体   English

动态添加/删除线程到芹菜中的工作池

[英]Dynamically add/remove threads to the worker pool in celery

How do I add more threads (and remove threads) to the current multiprocessing pool, from within a task (ie celeryd was run with CELERYD_CONCURRENCY = 10 but I want to change it on-the-fly to CELERYD_CONCURRENCY = 15)? 如何从任务中添加更多线程(并删除线程)到当前多处理池(即celeryd是在CELERYD_CONCURRENCY = 10下运行但我想在运行中将其更改为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. 有一个名为celery.concurrency.processes.TaskPool.Pool.grow的函数,但我不知道如何从正在运行的任务中调用它,或者它是否是正确的函数。

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. 虽然后者看起来有点可疑,但它们都有grow()shrink()

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. 警告海报:如果多处理实际上意味着运行多个单独的进程 ,那么当您尝试缩小或增长时,您可能已经处于子进程中,显然这将无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM