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

Created on 2017-09-13 12:25 by msekletar, last changed 2019-01-07 15:43 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11422 merged harman786, 2019-01-03 11:17
PR 11422 merged harman786, 2019-01-03 11:17
PR 11422 merged harman786, 2019-01-03 11:17
PR 11422 merged harman786, 2019-01-03 11:17
PR 11426 merged miss-islington, 2019-01-03 19:54
PR 11426 merged miss-islington, 2019-01-03 19:54
PR 11426 merged miss-islington, 2019-01-03 19:54
Messages (4)
msg302064 - (view) Author: Michal Sekletar (msekletar) Date: 2017-09-13 12:25
Issue
-----
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.


Reproducer
----------
$ cat preexec-exception.py
#!/usr/bin/env python3

import subprocess

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

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

    try:
        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
-------------
$ ./preexec-exception.py 
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 https://stackoverflow.com/questions/38433837/subprocess-child-traceback this seems to be the generic problem.

[1] https://docs.python.org/3/library/subprocess.html#exceptions
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.
msg332945 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2019-01-03 19:53
New changeset 47a2fced84605a32b79aa3ebc543533ad1a976a1 by Gregory P. Smith (Harmandeep Singh) in branch 'master':
bpo-31450: Remove documentation mentioning that subprocess's child_traceback is available with the parent process (GH-11422)
https://github.com/python/cpython/commit/47a2fced84605a32b79aa3ebc543533ad1a976a1
msg332946 - (view) Author: miss-islington (miss-islington) Date: 2019-01-03 20:01
New changeset 47c035f3efa77a439967776b5b6ba11d010ce466 by Miss Islington (bot) in branch '3.7':
bpo-31450: Remove documentation mentioning that subprocess's child_traceback is available with the parent process (GH-11422)
https://github.com/python/cpython/commit/47c035f3efa77a439967776b5b6ba11d010ce466
History
Date User Action Args
2019-01-07 15:43:57vstinnersetkeywords: patch, patch, patch, patch
status: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-01-03 20:01:48miss-islingtonsetnosy: + miss-islington
messages: + msg332946
2019-01-03 19:54:27miss-islingtonsetpull_requests: + pull_request10849
2019-01-03 19:54:21miss-islingtonsetpull_requests: + pull_request10848
2019-01-03 19:54:15miss-islingtonsetpull_requests: + pull_request10847
2019-01-03 19:53:58gregory.p.smithsetmessages: + msg332945
2019-01-03 11:17:39harman786setkeywords: + patch
stage: patch review
pull_requests: + pull_request10839
2019-01-03 11:17:32harman786setkeywords: + patch
stage: (no value)
pull_requests: + pull_request10838
2019-01-03 11:17:22harman786setkeywords: + patch
stage: (no value)
pull_requests: + pull_request10837
2019-01-03 11:17:16harman786setkeywords: + patch
stage: (no value)
pull_requests: + pull_request10836
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