(Only supported on Linux 2.5.44 and newer.) Return an edge polling object,
which can be used as Edge or Level Triggered interface for I/O
- events. *sizehint* and *flags* are deprecated and completely ignored.
+ events.
+
+ *sizehint* informs epoll about the expected number of events to be
+ registered. It must be positive, or `-1` to use the default. It is only
+ used on older systems where :c:func:`epoll_create1` is not available;
+ otherwise it has no effect (though its value is still checked).
+
+ *flags* is deprecated and completely ignored. However, when supplied, its
+ value must be ``0`` or ``select.EPOLL_CLOEXEC``, otherwise ``OSError`` is
+ raised.
See the :ref:`epoll-objects` section below for the methods supported by
epolling objects.
ep.close()
self.assertTrue(ep.closed)
self.assertRaises(ValueError, ep.fileno)
+
if hasattr(select, "EPOLL_CLOEXEC"):
- select.epoll(select.EPOLL_CLOEXEC).close()
+ select.epoll(-1, select.EPOLL_CLOEXEC).close()
select.epoll(flags=select.EPOLL_CLOEXEC).close()
select.epoll(flags=0).close()
- self.assertRaises(OSError, select.epoll, flags=12356)
def test_badcreate(self):
self.assertRaises(TypeError, select.epoll, 1, 2, 3)
self.assertRaises(TypeError, select.epoll, ['foo'])
self.assertRaises(TypeError, select.epoll, {})
+ self.assertRaises(ValueError, select.epoll, 0)
+ self.assertRaises(ValueError, select.epoll, -2)
+ self.assertRaises(ValueError, select.epoll, sizehint=-2)
+
+ if hasattr(select, "EPOLL_CLOEXEC"):
+ self.assertRaises(OSError, select.epoll, flags=12356)
+
def test_context_manager(self):
with select.epoll(16) as ep:
self.assertGreater(ep.fileno(), 0)
try:
# TypeError: argument must be an int, or have a fileno() method.
self.assertRaises(TypeError, ep.register, object(),
- select.EPOLLIN | select.EPOLLOUT)
+ select.EPOLLIN | select.EPOLLOUT)
self.assertRaises(TypeError, ep.register, None,
- select.EPOLLIN | select.EPOLLOUT)
+ select.EPOLLIN | select.EPOLLOUT)
# ValueError: file descriptor cannot be a negative integer (-1)
self.assertRaises(ValueError, ep.register, -1,
- select.EPOLLIN | select.EPOLLOUT)
+ select.EPOLLIN | select.EPOLLOUT)
# OSError: [Errno 9] Bad file descriptor
self.assertRaises(OSError, ep.register, 10000,
- select.EPOLLIN | select.EPOLLOUT)
+ select.EPOLLIN | select.EPOLLOUT)
# registering twice also raises an exception
ep.register(server, select.EPOLLIN | select.EPOLLOUT)
self.assertRaises(OSError, ep.register, server,
- select.EPOLLIN | select.EPOLLOUT)
+ select.EPOLLIN | select.EPOLLOUT)
finally:
ep.close()
ep = select.epoll(16)
ep.register(server.fileno(),
- select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
+ select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
ep.register(client.fileno(),
- select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
+ select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
now = time.monotonic()
events = ep.poll(1, 4)
static PyObject *
pyepoll_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- int flags = 0, sizehint = FD_SETSIZE - 1;
+ int flags = 0, sizehint = -1;
static char *kwlist[] = {"sizehint", "flags", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ii:epoll", kwlist,
&sizehint, &flags))
return NULL;
- if (sizehint < 0) {
- PyErr_SetString(PyExc_ValueError, "negative sizehint");
+ if (sizehint == -1) {
+ sizehint = FD_SETSIZE - 1;
+ }
+ else if (sizehint <= 0) {
+ PyErr_SetString(PyExc_ValueError, "sizehint must be positive or -1");
return NULL;
}
return NULL;
}
#endif
-
return newPyEpoll_Object(type, sizehint, -1);
}