This question just popped up with a bounty. The OP states:
This was an old question with an old and unsatisfying answer. Updated and added a bounty
Checking the revision history, it seems like the question changed pretty dramatically from the first version to the second version. So much so that the previous answer doesn't make a lot of sense — it refers to "distinguishing the errors from the process from the timeout", but that doesn't occur in the question anymore.
To complicate matters, the OP also added a bounty on the updated question.
What is the suggested direction for questions like this?
Note: I edited the question some for general style and clarity before I noticed the large change in content. You may want to ignore my changes for making any determinations.