denny <markfile...@126.com> added the comment: Hi David
I have tried in another testbd with python 2.6.5, and the problem of hang doesn't reproduce, after retrying for several times. The original hang happens in pipe.read of commands module. After comparing the code of python 2.4.4 and python 2.6.5, I noticed two enhancements in posimodule.c:posix_read. These defensive coding add precheck, before invoking read function. David, without these enhancements, would it cause the potential hang problem, in your opinion? Recompiling python 2.4.4 with some manual changes is a little scaring to me. ,----------- python 2.4.4 posixmodule.c | static PyObject * | posix_read(PyObject *self, PyObject *args) | { | int fd, size, n; | PyObject *buffer; | if (!PyArg_ParseTuple(args, "ii:read", &fd, &size)) | return NULL; | buffer = PyString_FromStringAndSize((char *)NULL, size); | if (buffer == NULL) | return NULL; | Py_BEGIN_ALLOW_THREADS | n = read(fd, PyString_AsString(buffer), size); | Py_END_ALLOW_THREADS | if (n < 0) { | Py_DECREF(buffer); | return posix_error(); | } | if (n != size) | _PyString_Resize(&buffer, n); | return buffer; | } `----------- ,----------- 2.6.5 posixmodule.c | static PyObject * | posix_read(PyObject *self, PyObject *args) | { | int fd, size, n; | PyObject *buffer; | if (!PyArg_ParseTuple(args, "ii:read", &fd, &size)) | return NULL; | if (size < 0) { | errno = EINVAL; | return posix_error(); | } | buffer = PyString_FromStringAndSize((char *)NULL, size); | if (buffer == NULL) | return NULL; | if (!_PyVerify_fd(fd)) | return posix_error(); | Py_BEGIN_ALLOW_THREADS | n = read(fd, PyString_AsString(buffer), size); | Py_END_ALLOW_THREADS | if (n < 0) { | Py_DECREF(buffer); | return posix_error(); | } | if (n != size) | _PyString_Resize(&buffer, n); | return buffer; | } `----------- ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue9532> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com