[issue38829] Make the function flush_io accessible in the C-API

2021-06-22 Thread Petr Viktorin


Petr Viktorin  added the comment:

To follow up on the StackOverflow discussion: A call to PyErr_Print should 
invoke sys.excepthook. Unless sys.excepthook was changed, this should print the 
message *and* flush standard output.
If it doesn't, I recommend investigating why.

If that does not work, you can flush stderr with two function calls:

sys_stderr = PySys_GetObject("stderr");
PyObject_CallMethodNoArgs(sys_stderr, "flush");

plus the necessary error handling if any returns NULL, of course.

And/or the same thing with stdout. The flush_io function does exactly this (for 
both stdout and stderr).
I don't think this is general enough to expose as an API -- IMO it's better to 
be explicit and call the flush method as above.

--
nosy: +petr.viktorin
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38829] Make the function flush_io accessible in the C-API

2019-12-09 Thread STINNER Victor


Change by STINNER Victor :


--
components: +C API -IO

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38829] Make the function flush_io accessible in the C-API

2019-11-17 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

PyObject_CallMethod(file, "flush", NULL)

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38829] Make the function flush_io accessible in the C-API

2019-11-17 Thread Jean-Didier


New submission from Jean-Didier :

Hello, 
when using an embedded python interpreter in a C++ program, which itself uses 
MPI, the embedded script's error messages are not flushed properly. 
(see the whole discussion in this StackOverflow : 
https://stackoverflow.com/questions/29352485/python-print-not-working-when-embedded-into-mpi-program/49076389#49076389).

The current preferred solution involves adding a few calls to flush_io in the 
C++. 
However, flush_io is a `static` function in `pythonrun.c`, and is not visible 
in the C-API.

Would it be possible to remove its static attribute, and add a reference to it 
in pythonrun.h?
Or maybe there is another method to flush IO from the C-API?

--
components: IO
messages: 356801
nosy: Jean-Didier
priority: normal
severity: normal
status: open
title: Make the function flush_io accessible in the C-API
type: enhancement
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com