Skip to content

Commit 2fb9ae9

Browse files
committed
add a flags parameter to select.epoll
1 parent e7437a7 commit 2fb9ae9

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

Doc/library/select.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,19 @@ The module defines the following:
3939

4040
.. versionadded:: 3.3
4141

42-
.. function:: epoll(sizehint=-1)
42+
.. function:: epoll(sizehint=-1, flags=0)
4343

44-
(Only supported on Linux 2.5.44 and newer.) Returns an edge polling object,
45-
which can be used as Edge or Level Triggered interface for I/O events; see
46-
section :ref:`epoll-objects` below for the methods supported by epolling
47-
objects.
44+
(Only supported on Linux 2.5.44 and newer.) Return an edge polling object,
45+
which can be used as Edge or Level Triggered interface for I/O
46+
events. *sizehint* is deprecated and completely ignored. *flags* can be set
47+
to :const:`EPOLL_CLOEXEC`, which causes the epoll descriptor to be closed
48+
automatically when :func:`os.execve` is called. See section
49+
:ref:`epoll-objects` below for the methods supported by epolling objects.
50+
51+
52+
.. versionchanged:: 3.3
53+
54+
Added the *flags* parameter.
4855

4956

5057
.. function:: poll()

Lib/test/test_epoll.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def test_create(self):
7474
ep.close()
7575
self.assertTrue(ep.closed)
7676
self.assertRaises(ValueError, ep.fileno)
77+
select.epoll(select.EPOLL_CLOEXEC).close()
78+
self.assertRaises(OSError, select.epoll, flags=12356)
7779

7880
def test_badcreate(self):
7981
self.assertRaises(TypeError, select.epoll, 1, 2, 3)

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ Core and Builtins
422422
Library
423423
-------
424424

425+
- Add a flags parameter to select.epoll.
426+
425427
- Issue #12798: Updated the mimetypes documentation.
426428

427429
- Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the

Modules/selectmodule.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,28 +1087,18 @@ pyepoll_internal_close(pyEpoll_Object *self)
10871087
}
10881088

10891089
static PyObject *
1090-
newPyEpoll_Object(PyTypeObject *type, int sizehint, SOCKET fd)
1090+
newPyEpoll_Object(PyTypeObject *type, int flags, SOCKET fd)
10911091
{
10921092
pyEpoll_Object *self;
10931093

1094-
if (sizehint == -1) {
1095-
sizehint = FD_SETSIZE-1;
1096-
}
1097-
else if (sizehint < 1) {
1098-
PyErr_Format(PyExc_ValueError,
1099-
"sizehint must be greater zero, got %d",
1100-
sizehint);
1101-
return NULL;
1102-
}
1103-
11041094
assert(type != NULL && type->tp_alloc != NULL);
11051095
self = (pyEpoll_Object *) type->tp_alloc(type, 0);
11061096
if (self == NULL)
11071097
return NULL;
11081098

11091099
if (fd == -1) {
11101100
Py_BEGIN_ALLOW_THREADS
1111-
self->epfd = epoll_create(sizehint);
1101+
self->epfd = epoll_create1(flags);
11121102
Py_END_ALLOW_THREADS
11131103
}
11141104
else {
@@ -1126,14 +1116,18 @@ newPyEpoll_Object(PyTypeObject *type, int sizehint, SOCKET fd)
11261116
static PyObject *
11271117
pyepoll_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
11281118
{
1129-
int sizehint = -1;
1130-
static char *kwlist[] = {"sizehint", NULL};
1119+
int flags = 0, sizehint = 0;
1120+
static char *kwlist[] = {"sizehint", "flags", NULL};
11311121

1132-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:epoll", kwlist,
1133-
&sizehint))
1122+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ii:epoll", kwlist,
1123+
&sizehint, &flags))
1124+
return NULL;
1125+
if (sizehint < 0) {
1126+
PyErr_SetString(PyExc_ValueError, "negative sizehint");
11341127
return NULL;
1128+
}
11351129

1136-
return newPyEpoll_Object(type, sizehint, -1);
1130+
return newPyEpoll_Object(type, flags, -1);
11371131
}
11381132

11391133

@@ -1191,7 +1185,7 @@ pyepoll_fromfd(PyObject *cls, PyObject *args)
11911185
if (!PyArg_ParseTuple(args, "i:fromfd", &fd))
11921186
return NULL;
11931187

1194-
return newPyEpoll_Object((PyTypeObject*)cls, -1, fd);
1188+
return newPyEpoll_Object((PyTypeObject*)cls, 0, fd);
11951189
}
11961190

11971191
PyDoc_STRVAR(pyepoll_fromfd_doc,
@@ -1420,7 +1414,7 @@ static PyGetSetDef pyepoll_getsetlist[] = {
14201414
};
14211415

14221416
PyDoc_STRVAR(pyepoll_doc,
1423-
"select.epoll([sizehint=-1])\n\
1417+
"select.epoll(sizehint=-1, flags=0)\n\
14241418
\n\
14251419
Returns an epolling object\n\
14261420
\n\
@@ -2218,6 +2212,8 @@ PyInit_select(void)
22182212
PyModule_AddIntConstant(m, "EPOLLWRNORM", EPOLLWRNORM);
22192213
PyModule_AddIntConstant(m, "EPOLLWRBAND", EPOLLWRBAND);
22202214
PyModule_AddIntConstant(m, "EPOLLMSG", EPOLLMSG);
2215+
2216+
PyModule_AddIntConstant(m, "EPOLL_CLOEXEC", EPOLL_CLOEXEC);
22212217
#endif /* HAVE_EPOLL */
22222218

22232219
#ifdef HAVE_KQUEUE

0 commit comments

Comments
 (0)