在 Django 项目中我想使用 ProcessPoolExecutor 但我可以做到。有什么解决办法吗?我在视图中调用了一个具有执行程序的函数。
我用的是Django==4.1.7.
应该向我的函数添加什么才能在 django 中运行。 start() 函数在 django 之外正常工作。但在 django 中不起作用。
从 django 应用程序中的 views.py 调用包含执行器的函数:
def start():
#'... some code here'
with concurrent.futures.ProcessPoolExecutor(max_workers=num_procs) as executor:
我推荐使用 Celery 从 Django 调用异步任务。这样您还可以跟踪流程和可能的错误。了解逻辑需要一点时间,但这是值得的。
https://docs.celeryq.dev/en/stable/index.html
https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html