As noted in Popen._internal_poll() docstring this method cannot reference anything outside of the local scope. However it references errno.ECHILD. The proposed patch fixes this. Is it good that Popen._handle_exitstatus() references building SubprocessError?
I'm just asking if this is a bug. If using building exceptions is safe, then we can get rid of _os_error and _ECHILD in 3.3+, using OSError and ChildProcessError instead.
it's a potential bug. your patch looks good. as for _handle_exitstatus referring to SubprocessError, that is fine. In that situation it is trying to raise the exception and the only time that would ever be a problem is when called by the gc during a __del__ where such an exception for this "impossible" situation cannot be caught anyways. It would effectively become an uncaught NameError instead of an uncaught SubprocessError; not a big deal.
As I can see in Py_Finalize finalized for standard exception classes is called after any python code has been finished, so we don't need to protect those exceptions.