I am working in a startup company where one of our microservice is in Python Flask and another in Java Spring. Between java and python code there is an asynchronous call for one task. When Python API is called from backend it starts it's service function in thread and returns 200 status to backend. Even when it's immediately returning 200 status, backend is throwing ReadTimeOutException.
Here is my Python Controller which is called from backend -
@cv_process_api.route("/parsecv", methods=['POST'])
def parsecv():
... some code ...
response = {}
response["statusCode"] = 200
response["responseBody"] = "Success"
Thread(target=parseResume, args=(fileName, cvRatingRequest, headers,)).start()
return response
We have observed that there are too many threads getting generated on prod and because of the new threads being created old threads are not getting the time to execute the return statement. Our system has 2 core and and one thread per core. What we saw on log was that thread 268 to thread 1423 were running simultaneously Here's the log :
Am I missing something ? Is my way of creating the thread is correct? How can I check if the older threads are getting killed? Any suggestions for improvement would be appreciated. Need quick reply, Thanks.