This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients davin, jnoller, martin.panter, pitrou, python-dev, sbt, serhiy.storchaka, vstinner
Date 2016-03-25.09:49:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1458899359.89.0.350228029075.issue25654@psf.upfronthosting.co.za>
In-reply-to
Content
> I don't know. I don't know why OSError and ValueError are caught at all.

Ha ha, me neither. Maybe it's time to remove them an wait for user feedback :-)

> What are you think about deterministic closing standard streams in cleanup_std_streams.patch? There is no haste to commit this.

This change has two parts.

For the "stdout.flush() ... stdout.close() ... stdout = None" part:

* It looks like a good idea to set stout (and stderr) to None, since I see many C code having an explicit "stream is None" check (handle correctly this case).
* For the flush part: I would prefer to share code with pylifecycle.c, flush_std_files(). Maybe we can log flush error into the C stderr stream? (Maybe with a flag when we know that Python finalization has started, or check _Py_Finalizing?)
* For the close part: I don't know. I like the idea of being able to use print until the last Python instruction.

Instead of closing and setting stdout/stderr to None, what do you think of using something similar than Py_Initialize():

    /* Set up a preliminary stderr printer until we have enough
       infrastructure for the io module in place. */
    pstderr = PyFile_NewStdPrinter(fileno(stderr));
    if (pstderr == NULL)
        Py_FatalError("Py_Initialize: can't set preliminary stderr");
    _PySys_SetObjectId(&PyId_stderr, pstderr);
    PySys_SetObject("__stderr__", pstderr);
    Py_DECREF(pstderr);

This printer has limitations, but it can help to get very late messages during Python finalization.

If we use this printer, it reduces the pressure on the exact order of operations.
History
Date User Action Args
2016-03-25 09:49:19vstinnersetrecipients: + vstinner, pitrou, jnoller, python-dev, sbt, martin.panter, serhiy.storchaka, davin
2016-03-25 09:49:19vstinnersetmessageid: <1458899359.89.0.350228029075.issue25654@psf.upfronthosting.co.za>
2016-03-25 09:49:19vstinnerlinkissue25654 messages
2016-03-25 09:49:19vstinnercreate