Title: Subprocess exceptions re-raised in parent process do not have child_traceback attribute
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.7, Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, cstratak, gregory.p.smith, msekletar
Priority: normal Keywords:

Created on 2017-09-13 12:25 by msekletar, last changed 2017-09-13 12:32 by christian.heimes.

Messages (2)
msg302064 - (view) Author: Michal Sekletar (msekletar) Date: 2017-09-13 12:25
Documentation of subprocess module claims that exceptions raised in child process will be re-raised in the parent process and will have child_traceback attribute set [1]. At least on Fedora Rawhide with python-3.6.2 this is not the case.

$ cat
#!/usr/bin/env python3

import subprocess

class PreExecCallback:
    def __call__(self):
        raise Exception()

if __name__ == "__main__":
    p = PreExecCallback()

        subprocess.Popen(['/bin/echo', 'foobar'], preexec_fn=p)
    except subprocess.SubprocessError as e:
        if not hasattr(e, 'child_traceback'):
            print('BUG: Exception happened in child, but exception object does not have child_traceback attribute')

Actual result
$ ./ 
BUG: Exception happened in child, but exception object does not have child_traceback attribute

Expected result
No output, because child_traceback attribute is present

Additional info
I happened to notice this while working with pre-exec callbacks. However, according to this seems to be the generic problem.

msg302066 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2017-09-13 12:32
Documentation and implementation are out of sync. Python 3's subprocess module no longer sets child_traceback. I checked 3.3 to master. The assignment has been removed.
Date User Action Args
2017-09-13 12:32:57christian.heimessetnosy: + gregory.p.smith, christian.heimes

messages: + msg302066
versions: + Python 3.7
2017-09-13 12:27:31cstrataksetnosy: + cstratak
2017-09-13 12:25:50msekletarcreate