def __init__(self, debug=False): self._handles = dict() self.debug = debug self._poll = select.poll() self._fd_r, self._fd_w = os.pipe() fcntl.fcntl(self._fd_r, fcntl.F_SETFL, os.O_NONBLOCK) self.register(self._fd_r, 'r', self._empty_fd)
def poll2(timeout=0.0, map=None): # Use the poll() support added to the select module in Python 2.0 if map is None: map = socket_map if timeout is not None: # timeout is in milliseconds timeout = int(timeout * 1000) pollster = select.poll() if map: for fd, obj in map.items(): flags = 0 if obj.readable(): flags |= select.POLLIN | select.POLLPRI if obj.writable(): flags |= select.POLLOUT if flags: # Only check for exceptions if object was either readable # or writable. flags |= select.POLLERR | select.POLLHUP | select.POLLNVAL pollster.register(fd, flags) try: r = pollster.poll(timeout) except select.error, err: if err[0] != EINTR: raise r = [] for fd, flags in r: obj = map.get(fd) if obj is None: continue readwrite(obj, flags)
def poll2(timeout=0.0, map=None): # Use the poll() support added to the select module in Python 2.0 if map is None: map = socket_map if timeout is not None: # timeout is in milliseconds timeout = int(timeout*1000) pollster = select.poll() if map: for fd, obj in map.items(): flags = 0 if obj.readable(): flags |= select.POLLIN | select.POLLPRI if obj.writable(): flags |= select.POLLOUT if flags: # Only check for exceptions if object was either readable # or writable. flags |= select.POLLERR | select.POLLHUP | select.POLLNVAL pollster.register(fd, flags) try: r = pollster.poll(timeout) except select.error, err: if err[0] != EINTR: raise r = [] for fd, flags in r: obj = map.get(fd) if obj is None: continue readwrite(obj, flags)
def __init__ (self, debug=False): self._handles = dict () self.debug = debug self._poll = select.poll () # self._locker = threading.Lock () # self._lock = self._locker.acquire # self._unlock = self._locker.release self._find_handle = self._handles.get self._get_ev = self.event_dict.__getitem__
import weakref from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, \ ENOTCONN, ESHUTDOWN, EINTR, EISCONN, errorcode FLAGS = select.POLLIN | select.POLLPRI | select.POLLERR | \ select.POLLHUP | select.POLLNVAL | select.POLLOUT try: socket_map except NameError: socket_map = {} try: pollster except NameError: pollster = select.poll() try: timers except NameError: timers = [] class ExitNow(Exception): pass def ticks(): return os.times()[4] def readwrite(obj, flags): try: if flags & (select.POLLIN | select.POLLPRI):
except ImportError: import select import errno, sys from zope.interface import implements # Twisted imports from twisted.python import log, threadable, failure from twisted.internet import main, posixbase, error from twisted.internet.interfaces import IReactorFDSet # globals reads = {} writes = {} selectables = {} poller = select.poll() POLL_DISCONNECTED = (select.POLLHUP | select.POLLERR | select.POLLNVAL) class PollReactor(posixbase.PosixReactorBase): """A reactor that uses poll(2).""" implements(IReactorFDSet) def _updateRegistration(self, fd): """Register/unregister an fd with the poller.""" try: poller.unregister(fd) except KeyError: pass
import errno, sys from zope.interface import implements # Twisted imports from twisted.python import log, threadable, failure from twisted.internet import main, posixbase, error from twisted.internet.interfaces import IReactorFDSet # globals reads = {} writes = {} selectables = {} poller = select.poll() POLL_DISCONNECTED = (select.POLLHUP | select.POLLERR | select.POLLNVAL) class PollReactor(posixbase.PosixReactorBase): """A reactor that uses poll(2).""" implements(IReactorFDSet) def _updateRegistration(self, fd): """Register/unregister an fd with the poller.""" try: poller.unregister(fd) except KeyError: pass
import weakref from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, \ ENOTCONN, ESHUTDOWN, EINTR, EISCONN, errorcode FLAGS = select.POLLIN | select.POLLPRI | select.POLLERR | \ select.POLLHUP | select.POLLNVAL | select.POLLOUT try: socket_map except NameError: socket_map = {} try: pollster except NameError: pollster = select.poll() try: timers except NameError: timers = [] class ExitNow(Exception): pass def ticks(): return os.times()[4]