Failed printing to stdout (when stdin is non blocking) | FFI

I am trying to debug this piece of code, where first I call fcntl to set the stdin as non blocking, then print in a loop. With the fcntl call, the print ultimately fails with the below error.

Rust Playground

thread 'main' panicked at 'failed printing to stdout: Resource temporarily unavailable (os error 11)', library/std/src/io/
stack backtrace:
   0: rust_begin_unwind
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/
   1: core::panicking::panic_fmt
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/
   2: std::io::stdio::print_to
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/io/
   3: std::io::stdio::_print
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/io/
   4: example1::main
             at ./examples/
   5: core::ops::function::FnOnce::call_once
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace

I am not sure what is going on. Here are some of the things I tried.

  1. Tried to reproduce the issue in C, but could not.
  2. Use 'Nightly'. Issue can be reproduced with Nightly toolchain.



  1. Part of a larger project, where FFI is required.
  2. Rust playground is throwing a Json error. Probably it is down, and not related to my problem.
  3. For some reason the said error is only seen if I redirected the stderr to a file. Without the redirection, the program will fail and exit, but no error is printed.

Non-blocking stdio isn't supported. You'll have to do something like using writeln! and handling recoverable errors yourself if you need non-blocking.

1 Like

Thanks. But why do you think writing to stdio is causing problems when stdin is the one non blocking?

Oh, I missed that, sorry. Perhaps this phenomenon.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.