Title: mywrite() ignores PyFile_WriteString() errors
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.1, Python 3.2
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: haypo
Priority: normal Keywords: patch

Created on 2010-03-12 16:08 by haypo, last changed 2010-04-23 12:05 by haypo. This issue is now closed.

File name Uploaded Description Edit
mywrite_nosignal.patch haypo, 2010-04-22 11:11
Messages (7)
msg100939 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2010-03-12 16:08
PyFile_WriteString() calls PyObject_Str() which calls PyErr_CheckSignals(). If a signal was catched, the signal handler is called. If the signal handler raises an error, PyObject_Str() and then PyFile_WriteString() return NULL.

mywrite() ignores all PyFile_WriteString() errors. It should maybe only ignores errors from the file (except IOError: ...) and not any error.

Another problem: mywrite() is called from PySys_WriteStdout() and PySys_WriteStderr() which are procedures. PySys_WriteStdout()/PySys_WriteStderr() caller cannot detect the error. There are 65 calls to PySys_WriteStd...
msg100942 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2010-03-12 16:10
This bug is related to #3137.
msg103711 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2010-04-20 14:11
Another solution: disable call to PyErr_CheckSignals() in mywrite().
msg103946 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2010-04-22 10:59
Attached patch fixes this issue: PyFile_WriteObject() doesn't call PyObject_Str() to avoid PyErr_CheckSignals(). I'm not sure that it's the right approch because it may change the behaviour of existing code when getting a signal.
msg103948 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2010-04-22 11:11
Ok, forget my pyfile_writeobject_nosignal.patch, it's not the right approach.

New patch: mywrite() uses its own implementation PyFile_WriteString(), sys_pyfile_write(), which doesn't call PyErr_CheckSignals():

/* Implementation of PyFile_WriteString() no calling PyErr_CheckSignals():
 * mywrite() should not execute any Python signal handler to avoid raising an
 * error because mywrite() ignores all errors */
msg103949 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2010-04-22 11:14
The goal is this issue is also to catch SIGINT when starting Python. It now works in Python trunk and py3k, but not in verbose mode because mywrite() eats errors (especially the KeyboardInterrupt raised by the default SIGINT handler) and calls indirectly Python signal handlers.
msg104006 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2010-04-23 12:05
Commited: r80404 (py3k), r80405 (3.1).
Date User Action Args
2010-04-23 12:05:11hayposetstatus: open -> closed
resolution: fixed
messages: + msg104006
2010-04-22 11:14:44hayposetmessages: + msg103949
2010-04-22 11:12:02hayposetfiles: - pyfile_writeobject_nosignal.patch
2010-04-22 11:11:42hayposetfiles: + mywrite_nosignal.patch

messages: + msg103948
2010-04-22 10:59:20hayposetfiles: + pyfile_writeobject_nosignal.patch
keywords: + patch
messages: + msg103946
2010-04-20 14:11:02hayposetmessages: + msg103711
2010-03-12 16:10:28hayposetmessages: + msg100942
2010-03-12 16:08:37haypocreate