← index #17541PR #6080
Related · high · value 1.453
QUERY · ISSUE

Compiling unix build with dupterm support fails on ubuntu

openby thatbudakguyopened 2025-06-21updated 2026-02-14
bug

Port, board and/or hardware

unix

MicroPython version

Micropython v1.24.1-dirty (from v1.24-release branch)

Reproduction

git clone -b v1.24-release --depth=1 --single-branch https://github.com/micropython/micropython.git
cd micropython
git submodule update --init
CFLAGS_EXTRA="-DMICROPY_PY_OS_DUPTERM=2" make -C ports/unix

This is executed on a GitHub actions runner (ubuntu-latest).

Expected behaviour

Finish compiling with a working os.dupterm.

Observed behaviour

This exception appears during compilation:

In file included from ../py/runtime.h:29,
                 from ../py/bc.h:30,
                 from ../py/emitglue.h:30,
                 from ../py/compile.h:31,
                 from ../py/runtime.c:35:
../py/runtime.c: In function ‘mp_init’:
../py/mpstate.h:312:40: error: ‘mp_state_vm_t’ {aka ‘struct _mp_state_vm_t’} has no member named ‘dupterm_objs’
  312 | #define MP_STATE_VM(x) (mp_state_ctx.vm.x)
      |                                        ^
../py/runtime.c:128:9: note: in expansion of macro ‘MP_STATE_VM’
  128 |         MP_STATE_VM(dupterm_objs[i]) = MP_OBJ_NULL;
      |         ^~~~~~~~~~~
-e See https://github.com/micropython/micropython/wiki/Build-Troubleshooting
make[1]: *** [../py/mkrules.mk:90: build/py/runtime.o] Error 1
make[1]: Leaving directory '/home/runner/work/mqterm/mqterm/micropython/mpy-cross'
make: *** [../../py/mkrules.mk:179: ../../mpy-cross/build/mpy-cross] Error 2
make: Leaving directory '/home/runner/work/mqterm/mqterm/micropython/ports/unix'

Additional Information

When compiling locally on my machine (M3 MacBook Pro), setting -DMICROPY_PY_OS_DUPTERM=2 correctly enables os.dupterm support.

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