Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

333
Vistas
¿Por qué las funciones Inline::Python que imprimen no se redireccionan?

Aquí está el reproducible más simple para mi problema:

 #!/usr/bin/env perl use 5.16.3; say "Got back ", test_print(); use Inline Python => <<'END_OF_PYTHON_CODE'; def test_print() -> int: print("In the python test print") return 32 END_OF_PYTHON_CODE

Cuando se ejecuta simplemente:

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

Pero cuando se redirige:

 $ perl small.pl | tee foo Got back 32 $ cat foo Got back 32

¿Qué podría estar haciendo mal para que el código Inline::Python no se imprima en una salida redirigida?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Py_Finalize() no se llama para destruir correctamente el intérprete de Python.

Afortunadamente, el módulo expone esta función como py_finalize , permitiéndonos llamarla nosotros mismos. Agregue lo siguiente a su programa:

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

Manifestación:

 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 END { Inline::Python::py_finalize() if $ARGV[0]; } say "Got back ", test_print();
 $ perl a.pl 0 In the python test print Got back 32 $ perl a.pl 0 | cat Got back 32 $ perl a.pl 1 In the python test print Got back 32 $ perl a.pl 1 | cat In the python test print Got back 32
over 4 years ago · Santiago Trujillo Denunciar

0

Lo completo que hay que hacer es:

 BEGIN { # Unbuffer Python's output $ENV{PYTHONUNBUFFERED}=1; # Unbuffer Perl's output select((select(STDOUT), $|=1)[0]); select((select(STDERR), $|=1)[0]); } ... END { # Shut down the Python interpreter. Inline::Python::py_finalize(); }

También debe quitar el búfer de la salida de Perl. Gracias a ikegami que comentó en ese sentido en una publicación ahora eliminada y me recordó sobre py_finalize() .

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda