This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Add '-d $fd' option to trace module, akin to bash -x feature
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.11
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: PenelopeFudd
Priority: normal Keywords: patch

Created on 2022-02-13 21:39 by PenelopeFudd, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 31319 open PenelopeFudd, 2022-02-13 22:23
Messages (1)
msg413197 - (view) Author: Charles Howes (PenelopeFudd) * Date: 2022-02-13 21:39
The 'trace' module logs trace output to stdout, intermingled with regular program output.  This is a problem when you want to read either the trace output or the normal output of the program separately.

To separate the trace output, it could be written to a file or to another file descriptor.

A pull request has been created that fixes this by mimicking bash's behaviour: bash can be told to write trace output to a different file descriptor using the BASH_XTRACEFD shell variable: `exec 42> xtrace.out; BASH_XTRACEFD=42; ...`

Usage of this new feature:

  python -m trace -t -d 111 111> /tmp/your_trace.txt


  t = Trace(count=1, trace=1, trace_fd=1, countfuncs=0, countcallers=0, ignoremods=(), ignoredirs=(), infile=None, outfile=None, timing=False)

* `bash -x` sends trace logs to stderr by default; `python -m trace -t` sends them to stdout.  I wanted to change Python to match, but was worried that this might break existing code.  

* Also considered writing trace logs to the file specified with the `-f FILE` option, but worried that it would mess up the count file if `-t` and `-c` were used together.
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90898
2022-02-13 22:23:56PenelopeFuddsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29478
2022-02-13 21:39:31PenelopeFuddcreate