New submission from Charles Howes <github....@ch.pkts.ca>:

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 your_program.py 111> /tmp/your_trace.txt

or:

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

Notes:
* `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.

----------
components: Library (Lib)
messages: 413197
nosy: PenelopeFudd
priority: normal
severity: normal
status: open
title: Add '-d $fd' option to trace module, akin to bash -x feature
type: enhancement
versions: Python 3.11

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46742>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to