我正在研究一个小但计算密集的Python应用程序.计算密集型工作可以分成几个可以同时执行的部分.我试图找到一个合适的堆栈来实现这一目标.
目前我计划在Apache2 WSGI上使用带有Celery的Flask应用程序作为任务队列.
在下面,如果有3个或更多工作者可用,a_long_process(),another_long_process()和yet_another_long_process()会同时执行吗?在进程执行时是否会阻止Flask应用程序?
来自Flask app:
@myapp.route('/foo')
def bar():
task_1 = a_long_process.delay(x, y)
task_1_result = task_1.get(timeout=1)
task_2 = another_long_process.delay(x, y)
task_2_result = task_2.get(timeout=1)
task_3 = yet_another_long_process.delay(x, y)
task_3_result = task_3.get(timeout=1)
return task_1 + task_2 + task_3
tasks.py:
from celery import Celery
celery = Celery('tasks', broker="amqp://guest@localhost//", backend="amqp://")
@celery.task
def a_long_process(x, y):
return something
@celery.task
def another_long_process(x, y):
return something_else
@celery.task
def yet_another_long_process(x, y):
return a_third_thing