--- Modules/selectmodule.c.orig 2006-07-09 18:18:57.000000000 -0700 +++ Modules/selectmodule.c 2007-07-24 17:16:44.000000000 -0700 @@ -452,7 +452,7 @@ poll_poll(pollObject *self, PyObject *args) { PyObject *result_list = NULL, *tout = NULL; - int timeout = 0, poll_result, i, j; + int timeout = 0, poll_result, i, j, num_descriptors; PyObject *value = NULL, *num = NULL; if (!PyArg_UnpackTuple(args, "poll", 0, 1, &tout)) { @@ -491,14 +491,21 @@ PyErr_SetFromErrno(SelectError); return NULL; } - + + /* count the number of fired descriptors */ + num_descriptors = 0; + for (i = 0; i < self->ufd_len; i++) { + if (self->ufds[i].revents) + num_descriptors++; + } + /* build the result list */ - result_list = PyList_New(poll_result); + result_list = PyList_New(num_descriptors); if (!result_list) return NULL; else { - for (i = 0, j = 0; j < poll_result; j++) { + for (i = 0, j = 0; j < num_descriptors; j++) { /* skip to the next fired descriptor */ while (!self->ufds[i].revents) { i++;