Preventing deadlock on subprocess.Popen.poll()

According to
http://docs.python.org/2/library/subprocess.html#subprocess.Popen.poll

Warning: This will deadlock when using stdout=PIPE and/or stderr=PIPE
and the child process generates enough output to a pipe such that it
blocks waiting for the OS pipe buffer to accept more data.
Use communicate() to avoid that.
We count consecutive iterations that do not have any output, and
only if it reaches a certain threshold, self.communicate() is run.
Merge pull request #9110 from pakdel/subprocess.Popen.poll_deadlock

Preventing deadlock on subprocess.Popen.poll()