I have a python code which on profiling with cProfile always gives the following data.
`299149 function calls (294133 primitive calls) in 39.049 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
2 36.532 18.266 36.532 18.266 {posix.waitpid}
39 1.769 0.045 1.769 0.045 {method 'query' of '_mysql.connection' objects}
1 0.120 0.120 0.167 0.167 connections.py:62(__init__)
2 0.083 0.042 0.083 0.042 {method 'rollback' of '_mysql.connection' objects}`
Now the only way I suspect the code to be blocking on posix.waitpid is because of the following function.
process = Popen(command, stdout=PIPE)
return process.communicate()
This is explained fairly well in python subprocess communicate() block .
The method executeCommand is called from a lot of places in the code .
and in another place where it iterates over a list of URLs and executes the curl command. This can be very bad performance bottleneck as this will block for the entire subprocesses to finish.
My question is why cProfile output shows me only 2 in nCalls column although the call to executeCommand
function is made multiple times in the code.
If the culprit is what I suspect to be , is there a workaround for this problem.