From: Ben Darnell Date: Mon, 14 Jan 2013 02:59:21 +0000 (-0500) Subject: Remove our custom epoll module now that we only support 2.6+. X-Git-Tag: v3.0.0~176 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=217b7eb5fc4d923b9abb3fe22cc2abd213b1dfb4;p=thirdparty%2Ftornado.git Remove our custom epoll module now that we only support 2.6+. --- diff --git a/setup.py b/setup.py index efa27ac00..a91acb56d 100644 --- a/setup.py +++ b/setup.py @@ -25,14 +25,6 @@ except ImportError: kwargs = {} -# Build the epoll extension for Linux systems with Python < 2.6 -extensions = [] -major, minor = sys.version_info[:2] -python_26 = (major > 2 or (major == 2 and minor >= 6)) -if "linux" in sys.platform.lower() and not python_26: - extensions.append(distutils.core.Extension( - "tornado.epoll", ["tornado/epoll.c"])) - version = "2.4.post2" distutils.core.setup( @@ -55,7 +47,6 @@ distutils.core.setup( "gettext_translations/fr_FR/LC_MESSAGES/tornado_test.po", ], }, - ext_modules = extensions, author="Facebook", author_email="python-tornado@googlegroups.com", url="http://www.tornadoweb.org/", diff --git a/tornado/epoll.c b/tornado/epoll.c deleted file mode 100644 index 9a2e3a374..000000000 --- a/tornado/epoll.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2009 Facebook - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -#include "Python.h" -#include -#include - -#define MAX_EVENTS 24 - -/* - * Simple wrapper around epoll_create. - */ -static PyObject* _epoll_create(void) { - int fd = epoll_create(MAX_EVENTS); - if (fd == -1) { - PyErr_SetFromErrno(PyExc_Exception); - return NULL; - } - - return PyInt_FromLong(fd); -} - -/* - * Simple wrapper around epoll_ctl. We throw an exception if the call fails - * rather than returning the error code since it is an infrequent (and likely - * catastrophic) event when it does happen. - */ -static PyObject* _epoll_ctl(PyObject* self, PyObject* args) { - int epfd, op, fd, events; - struct epoll_event event; - - if (!PyArg_ParseTuple(args, "iiiI", &epfd, &op, &fd, &events)) { - return NULL; - } - - memset(&event, 0, sizeof(event)); - event.events = events; - event.data.fd = fd; - if (epoll_ctl(epfd, op, fd, &event) == -1) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_INCREF(Py_None); - return Py_None; -} - -/* - * Simple wrapper around epoll_wait. We return None if the call times out and - * throw an exception if an error occurs. Otherwise, we return a list of - * (fd, event) tuples. - */ -static PyObject* _epoll_wait(PyObject* self, PyObject* args) { - struct epoll_event events[MAX_EVENTS]; - int epfd, timeout, num_events, i; - PyObject* list; - PyObject* tuple; - - if (!PyArg_ParseTuple(args, "ii", &epfd, &timeout)) { - return NULL; - } - - Py_BEGIN_ALLOW_THREADS - num_events = epoll_wait(epfd, events, MAX_EVENTS, timeout); - Py_END_ALLOW_THREADS - if (num_events == -1) { - PyErr_SetFromErrno(PyExc_Exception); - return NULL; - } - - list = PyList_New(num_events); - for (i = 0; i < num_events; i++) { - tuple = PyTuple_New(2); - PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(events[i].data.fd)); - PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(events[i].events)); - PyList_SET_ITEM(list, i, tuple); - } - return list; -} - -/* - * Our method declararations - */ -static PyMethodDef kEpollMethods[] = { - {"epoll_create", (PyCFunction)_epoll_create, METH_NOARGS, - "Create an epoll file descriptor"}, - {"epoll_ctl", _epoll_ctl, METH_VARARGS, - "Control an epoll file descriptor"}, - {"epoll_wait", _epoll_wait, METH_VARARGS, - "Wait for events on an epoll file descriptor"}, - {NULL, NULL, 0, NULL} -}; - -/* - * Module initialization - */ -PyMODINIT_FUNC initepoll(void) { - Py_InitModule("epoll", kEpollMethods); -} diff --git a/tornado/ioloop.py b/tornado/ioloop.py index 9154d11be..4731564cd 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -182,13 +182,9 @@ class IOLoop(Configurable): @classmethod def configurable_default(cls): - if hasattr(select, "epoll") or sys.platform.startswith('linux'): - try: - from tornado.platform.epoll import EPollIOLoop - return EPollIOLoop - except ImportError: - gen_log.warning("unable to import EPollIOLoop, falling back to SelectIOLoop") - pass + if hasattr(select, "epoll"): + from tornado.platform.epoll import EPollIOLoop + return EPollIOLoop if hasattr(select, "kqueue"): # Python 2.6+ on BSD or Mac from tornado.platform.kqueue import KQueueIOLoop diff --git a/tornado/platform/epoll.py b/tornado/platform/epoll.py index cc8c0c6f5..2b20a41bd 100644 --- a/tornado/platform/epoll.py +++ b/tornado/platform/epoll.py @@ -13,11 +13,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -"""EPoll-based IOLoop implementation for Linux systems. - -Supports the standard library's `select.epoll` function for Python 2.6+, -and our own C module for Python 2.5. -""" +"""EPoll-based IOLoop implementation for Linux systems.""" from __future__ import absolute_import, division, print_function, with_statement import os @@ -25,44 +21,6 @@ import select from tornado.ioloop import PollIOLoop -if hasattr(select, 'epoll'): - # Python 2.6+ - class EPollIOLoop(PollIOLoop): - def initialize(self, **kwargs): - super(EPollIOLoop, self).initialize(impl=select.epoll(), **kwargs) -else: - # Python 2.5 - from tornado import epoll - - class _EPoll(object): - """An epoll-based event loop using our C module for Python 2.5 systems""" - _EPOLL_CTL_ADD = 1 - _EPOLL_CTL_DEL = 2 - _EPOLL_CTL_MOD = 3 - - def __init__(self): - self._epoll_fd = epoll.epoll_create() - - def fileno(self): - return self._epoll_fd - - def close(self): - os.close(self._epoll_fd) - - def register(self, fd, events): - epoll.epoll_ctl(self._epoll_fd, self._EPOLL_CTL_ADD, fd, events) - - def modify(self, fd, events): - epoll.epoll_ctl(self._epoll_fd, self._EPOLL_CTL_MOD, fd, events) - - def unregister(self, fd): - epoll.epoll_ctl(self._epoll_fd, self._EPOLL_CTL_DEL, fd, 0) - - def poll(self, timeout): - return epoll.epoll_wait(self._epoll_fd, int(timeout * 1000)) - - - class EPollIOLoop(PollIOLoop): - def initialize(self, **kwargs): - super(EPollIOLoop, self).initialize(impl=_EPoll(), **kwargs) - +class EPollIOLoop(PollIOLoop): + def initialize(self, **kwargs): + super(EPollIOLoop, self).initialize(impl=select.epoll(), **kwargs)