s/break/return/ to break out of the outer loop; use .communicate() to avoid deadlock