File: epolls.py

package info (click to toggle)
python-eventlet 0.26.1-7%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,916 kB
  • sloc: python: 24,898; makefile: 98
file content (31 lines) | stat: -rw-r--r-- 1,027 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import errno
from eventlet import patcher, support
from eventlet.hubs import hub, poll
select = patcher.original('select')


def is_available():
    return hasattr(select, 'epoll')


# NOTE: we rely on the fact that the epoll flag constants
# are identical in value to the poll constants
class Hub(poll.Hub):
    def __init__(self, clock=None):
        super(Hub, self).__init__(clock=clock)
        self.poll = select.epoll()

    def add(self, evtype, fileno, cb, tb, mac):
        oldlisteners = bool(self.listeners[self.READ].get(fileno) or
                            self.listeners[self.WRITE].get(fileno))
        # not super() to avoid double register()
        listener = hub.BaseHub.add(self, evtype, fileno, cb, tb, mac)
        try:
            self.register(fileno, new=not oldlisteners)
        except IOError as ex:    # ignore EEXIST, #80
            if support.get_errno(ex) != errno.EEXIST:
                raise
        return listener

    def do_poll(self, seconds):
        return self.poll.poll(seconds)