Added a try/except block to catch broken pipe IOErrors. I'm not sure what is causing them, but there will be a 5 second timeout and then a reattempt.