Hi Kel,
We are having issues with multiprocessing code in production as well. We have a controller function that spawns a new Process (process.start()), and then this control is supposed to return a response
immediately WITHOUT waiting for the spawned Process to finish. After the controller function returns, the spawned Process is supposed to continue running till its end. So it is kind of a non-blocking/async call.
The code works in dev mode locally. But in production mode the controller doesn't return until the spawned process finishes -- becoming a blocking/sync call.
I have been searching online over the weekend and have tried different methods but it is still not working. I tried different combinations of the following options in uwsgi service yml file with no luck:
close-on-exec: true
lazy-apps: true
enable-threads: true
buffer-size: 32768
post-buffering: true
gevent: 100
async: true
I took a quick look at your code. If I understand it correctly you want to your controller to wait for the spawned Processes to finish, right? What error or unexpected behavior you saw in production?
I will keep you updated on my progress. Please also post back your progress.
Thanks
Drew
@BYU
Our code is like this:
import multiprocessing
import time
def newProcessFunc():
print "newProcessFunc Start"
# do something here
time.sleep(30) # sleep 30 second
print "newProcessFunc Stop"
def myControllerFunc (request):
print "myControllerFunc Start"
# spawn a new process
p = multiprocessing.Process(target=newProcessFunc)
p.start()
print "myControllerFunc End"
return JsonResponse({''status": "success"})