Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Python integration buffering issue #487

Open
aofei opened this issue Jul 10, 2024 · 0 comments
Open

bug: Python integration buffering issue #487

aofei opened this issue Jul 10, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@aofei
Copy link
Member

aofei commented Jul 10, 2024

Description

There is a bug in the Python integration that needs to be addressed.

When running the following command:

llgo run ./_pydemo/callpy/

The output is displayed correctly. However, when running:

llgo run ./_pydemo/callpy/ > output.txt && cat output.txt

There is no output.

Root cause

The root cause of this issue appears to be related to Python's default buffering mode. By default, Python uses buffered I/O for sys.stdin, sys.stdout, and sys.stderr.

  • In the 1st case, the output is shown in the console because it uses line buffering.
  • In the 2nd case, the output is not captured in output.txt because it uses full buffering, and the buffer is not flushed before the program exits.

Workarounds

The issue can be temporarily fixed by disabling Python's buffering mode manually:

export PYTHONUNBUFFERED=1

Possible solutions

To resolve this issue in llgo,

  • it may be necessary to switch Python to unbuffered mode;
  • or provide a manual flush option, though this could be cumbersome for users;
  • or ensure the buffer is flushed before the program exits to retain Python's default design.

For reference, Go's os.Stdin, os.Stdout, and os.Stderr are always unbuffered (see: golang-nuts).

@xushiwei xushiwei added the bug Something isn't working label Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants