From 3e0b46b9af8b7a6934b7ac68671ef8f55be2b848 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 4 Mar 2020 12:39:55 +1100 Subject: [PATCH] unix/file: Don't raise OSError(EINVAL) on sys.stdin/out/err.flush(). sys.stdout.flush() is needed on CPython to flush the output, and the change in this commit makes such an expression also work on MicroPython (although MicroPython doesn't actual need to do any flushing). --- ports/unix/file.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ports/unix/file.c b/ports/unix/file.c index 0fe4f98782..ed05fe7332 100644 --- a/ports/unix/file.c +++ b/ports/unix/file.c @@ -126,6 +126,13 @@ STATIC mp_uint_t fdfile_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, i int ret = fsync(o->fd); MP_THREAD_GIL_ENTER(); if (ret == -1) { + if (errno == EINVAL + && (o->fd == STDIN_FILENO || o->fd == STDOUT_FILENO || o->fd == STDERR_FILENO)) { + // fsync(stdin/stdout/stderr) may fail with EINVAL, but don't propagate that + // error out. Because data is not buffered by us, and stdin/out/err.flush() + // should just be a no-op. + return 0; + } *errcode = errno; return MP_STREAM_ERROR; }