예제 #1
0
파일: io_poll.py 프로젝트: hackudown/vps
 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)
예제 #2
0
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)
예제 #3
0
파일: async.py 프로젝트: chinnurtb/mrim
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)
예제 #4
0
    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__
예제 #5
0
파일: async.py 프로젝트: chinnurtb/mrim
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):
예제 #6
0
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
예제 #7
0

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
예제 #8
0
파일: async.py 프로젝트: nivertech/mrim
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]