You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?: Homebrew; python3 -m virtualenv .venv
Your Rust version (rustc --version): rustc 1.50.0 (cb75ad5db 2021-02-10)
Your PyO3 version: 0.13.2
Have you tried using latest PyO3 master (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")?: Yes, reproduces after fixing compilation errors.
use pyo3::prelude::*;fnmain() -> PyResult<()>{Python::with_gil(|py| {let testing = PyModule::import(py,"testing")?;
testing.call0("foo")?;Ok(())})}
testing.py:
importsysdeffoo():
sys.stdout.write("Hello, world!")
# Uncomment to fix issue:# sys.stdout.flush()
Note that the issue doesn't reproduce if the output ends with a newline character. Presumably that automatically flushes stdout.
This is probably due to #1355. I understand that running finalizers might break some C code, but perhaps a special case can be made for flushing stdout/stderr? It's an idempotent operation, and it might take a long time for someone to debug the issue otherwise.
If you don't want to change this behavior, then a note in the documentation somewhere would be helpful.
The text was updated successfully, but these errors were encountered:
arxanas
added a commit
to arxanas/git-branchless
that referenced
this issue
Mar 12, 2021
Hi @arxanas we added the finalizers to flush stdout and then removed them in #1355 as you note because of the C code and also async issues. In the end we decided there's too many issues with finalizers to run them ourselves. So I think this is a documentation issue.
You may want to consider running with PYTHONUNBUFFERED=1 if you've got stdout being printed from both Rust and Python, so that ordering remains consistent. This will also avoid the need to call flush manually at program exit 馃槂
Alternatively you could add unsafe { pyo3::ffi::Py_Finalize() } at the end of your main function if it doesn't cause you problems.
馃實 Environment
python3 -m virtualenv .venv
rustc --version
): rustc 1.50.0 (cb75ad5db 2021-02-10)version = "0.x.y"
withgit = "https://github.com/PyO3/pyo3")?
: Yes, reproduces after fixing compilation errors.馃挜 Reproducing
Clone https://github.com/arxanas/pyo3-bug and run
PYTHONPATH=. cargo run
in the root directory.main.rs:
testing.py:
Note that the issue doesn't reproduce if the output ends with a newline character. Presumably that automatically flushes stdout.
This is probably due to #1355. I understand that running finalizers might break some C code, but perhaps a special case can be made for flushing stdout/stderr? It's an idempotent operation, and it might take a long time for someone to debug the issue otherwise.
If you don't want to change this behavior, then a note in the documentation somewhere would be helpful.
The text was updated successfully, but these errors were encountered: