Issue #8865: Concurrent invocation of select.poll.poll() now raises a

RuntimeError exception.  Patch by Christian Schubert.
This commit is contained in:
Serhiy Storchaka 2013-08-20 20:50:32 +03:00
commit 5617df1be6
4 changed files with 57 additions and 2 deletions

View file

@ -327,6 +327,7 @@ typedef struct {
int ufd_uptodate;
int ufd_len;
struct pollfd *ufds;
int poll_running;
} pollObject;
static PyTypeObject poll_Type;
@ -523,16 +524,27 @@ poll_poll(pollObject *self, PyObject *args)
return NULL;
}
/* Avoid concurrent poll() invocation, issue 8865 */
if (self->poll_running) {
PyErr_SetString(PyExc_RuntimeError,
"concurrent poll() invocation");
return NULL;
}
/* Ensure the ufd array is up to date */
if (!self->ufd_uptodate)
if (update_ufd_array(self) == 0)
return NULL;
self->poll_running = 1;
/* call poll() */
Py_BEGIN_ALLOW_THREADS
poll_result = poll(self->ufds, self->ufd_len, timeout);
Py_END_ALLOW_THREADS
self->poll_running = 0;
if (poll_result < 0) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
@ -609,6 +621,7 @@ newPollObject(void)
array pointed to by ufds matches the contents of the dictionary. */
self->ufd_uptodate = 0;
self->ufds = NULL;
self->poll_running = 0;
self->dict = PyDict_New();
if (self->dict == NULL) {
Py_DECREF(self);