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

Python's STDOUT isn't flushed #32

Open
ikegami opened this issue Aug 4, 2021 · 8 comments
Open

Python's STDOUT isn't flushed #32

ikegami opened this issue Aug 4, 2021 · 8 comments

Comments

@ikegami
Copy link

ikegami commented Aug 4, 2021

As reported on StackOverflow, Python's STDOUT isn't flushed

use feature qw( say );

use Inline Python => <<'END_OF_PYTHON_CODE';

def test_print() -> int:
    print("In the python test print")
    return 32

END_OF_PYTHON_CODE

say "Got back ", test_print();

Output:

$ perl a.pl
In the python test print
Got back 32

$ perl a.pl | cat
Got back 32

Who knows what other destruction doesn't occur.

@ikegami
Copy link
Author

ikegami commented Aug 5, 2021

One can work around this issue by adding the following to one's program:

END { Inline::Python::py_finalize(); }

@matthewpersico
Copy link

That doesn't quite solve the output issue. See here; we get all the output, but it is scrambled.

@ikegami
Copy link
Author

ikegami commented Aug 5, 2021

That doesn't quite solve the output issue. See here; we get all the output, but it is scrambled.

That's expected, completely normal, and not a bug in the module.

@matthewpersico
Copy link

That's expected, completely normal, and not a bug in the module.

Then it might warrant a comment in the docs. Would you take a PR for such?

@ikegami
Copy link
Author

ikegami commented Aug 17, 2021

That's expected, completely normal, and not a bug in the module.

Then it might warrant a comment in the docs. Would you take a PR for such?

Whenever you have two things trying to use one resource (e.g. a terminal), coordination (e.g. synchronization) is required, or at least needs to be considered.

@matthewpersico
Copy link

Whenever you have two things trying to use one resource (e.g. a terminal), coordination (e.g. synchronization) is required, or at least needs to be considered.

Yes, I see now. Here, we have two interpreters running, each with its own process space. Would this be an issue if we were inlining a compiled language? I would think not because then the inline'd code is just a library being executed in the Perl process space.

The distinction is important to me in terms of how I want to propose a documentation PR - I propose it would go in the Inline docs themselves under a heading like "Considering Non-Compiled Inline Modules"

@niner
Copy link
Owner

niner commented Aug 18, 2021 via email

@ikegami
Copy link
Author

ikegami commented Aug 18, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants