I need to run my logic parallelly using all available CPUs, for that I am using billiard package for pooling, PFB my technology stack -
-Python 3
-Django==2.0.5
-Django rest from work
-celery==4.2.0
My problem is, when I am hitting my rest-API and triggering my celery task it executes till pooling line but after that, its getting hang, I am not getting any error message but It is not moving further.
#cmdapp.helper.aaa.py
from billiard.pool import Pool
class A():
def squre(self,number):
return number*number
def calculate(self,number_list):
pool = Pool()
result = pool.map(self.squre, number_list)
return result
#cmdapp.tasks.bbb.py
from celery import task
from cmdapp.helper.aaa import A
@task
def calculation_task(number_list):
a_obj=A()
result=a_obj.calculate(number_list)
#cmdapp.api.ccc.py
from rest_framework.views import APIView
from rest_framework import status, permissions
from rest_framework.response import Response
from cmdapp.tasks.bbb import calculation_task
class C(APIView):
def get(self, request):
range_list=range(1000)
calculation_task.delay(range_list)
return Response({
"result": "success",
}, status=status.HTTP_200_OK)
I went through some articles where they have mentioned unpickable function cannot be called by pool.map function. Here I am not getting my function is pickable or unpickable and why It is getting a hang. Please help in that.
I need to run my logic parallelly using all available CPUs, for that I am using billiard package for pooling, PFB my technology stack -
My problem is, when I am hitting my rest-API and triggering my celery task it executes till pooling line but after that, its getting hang, I am not getting any error message but It is not moving further.
PFB my project structure:
PFB my code example:
I went through some articles where they have mentioned unpickable function cannot be called by pool.map function. Here I am not getting my function is pickable or unpickable and why It is getting a hang. Please help in that.