I have a webservice that initiates a process that can take up to a minute. I want to return a 204 that effectively says, "I have successfully gotten your request," but run the slow process in the background.
I am trying to do this by forking another process like this:
p = Process(target = modelObj.slowProcess)
p.start()
logger.debug('sending 204')
return HttpResponse( status=204)
This part of the code seems to execute fine, but is tripping up django components. The debug statement is printed, and the process executes, but when I look at the network traffic in chrome's debugger, it says that the upload status is "cancelled". Since I haven't cancelled the event on the browser side, I assume that means the connection died. I never get any response back from the server, so it seems that I'm somehow breaking the request process.
How can I fork that separate process and still have the 204 get delivered?
Copyright Notice:Content Author:「BostonJohn」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/20958666/forking-a-process-within-a-django-view