Skip to content

Python's STDOUT isn't flushed #32

Open

Description

@ikegami

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.

Activity

  1. ikegami commented on Aug 5, 2021

    @ikegami
    Author

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

    END { Inline::Python::py_finalize(); }
  2. matthewpersico commented on Aug 5, 2021

    @matthewpersico

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

  3. ikegami commented on Aug 5, 2021

    @ikegami
    Author

    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.

  4. matthewpersico commented on Aug 16, 2021

    @matthewpersico

    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?

  5. ikegami commented on Aug 17, 2021

    @ikegami
    Author

    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.

  6. matthewpersico commented on Aug 18, 2021

    @matthewpersico

    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"

  7. niner commented on Aug 18, 2021

    @niner
    Owner
  8. ikegami commented on Aug 18, 2021

    @ikegami
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions