← index #18837PR #6080
Related · medium · value 0.338
QUERY · ISSUE

Enabling DUPTERM on Unix kills output to stderr

openby smurfixopened 2026-02-18updated 2026-03-14
bugport-unix

Port, board and/or hardware

Unix

MicroPython version

current master, v1.27.0-175-ga8b71559cf-dirty

Reproduction

Adding

#define MICROPY_PY_OS_DUPTERM (2)

to ports/unix/mpconfigport.h disables writing to standard error. Output is sent to stdout instead.

Expected behaviour

$ ports/unix/build-standard/micropython -c "import sys;print('XXX',file=sys.stderr)" >/dev/null
XXX
$ 

Observed behaviour

$ ports/unix/build-standard/micropython -c "import sys;print('XXX',file=sys.stderr)" >/dev/null
[ no output ]
$ 

Additional Information

>>> import sys
>>> sys.stdout
<io.TextIOWrapper 1>
>>> sys.stderr
<io.TextIOWrapper 2>

but print or write don't seem to care.

Code of Conduct

Yes, I agree

CANDIDATE · PULL REQUEST

ports/unix: Add full uos.dupterm support.

openby andrewleechopened 2020-05-27updated 2026-03-23
port-unix

The unix port currently supports a very limited uos.dupterm implementation.
It can only replace stdin and/or duplicate stdout.
When using uos.dupterm to replace slot 0 it does not return a handle to the existing (posix stdio) stream.

This PR resolves these issues, preferring to use dupterm for all stdio on unix when MICROPY_PY_OS_DUPTERM=1 is configured in the build.

With this change simple modification of the output stream is possible, for example to format logging messaging with a basic timestamp

stdio = None

class logger:
    def write(self, buf):
        global stdio        
        stdio.write(str(utime.time()))
        stdio.write(" | ")
        stdio.write(buf)

stdio = uos.dupterm(logger(), 0)

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied