|
|
@ -1912,6 +1912,8 @@ class Poller(object):
|
|
|
|
|
|
|
|
|
|
|
|
Pollers may only be used by one thread at a time.
|
|
|
|
Pollers may only be used by one thread at a time.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
SUPPORTED = True
|
|
|
|
|
|
|
|
|
|
|
|
# This changed from select() to poll() in Mitogen 0.2.4. Since poll() has
|
|
|
|
# This changed from select() to poll() in Mitogen 0.2.4. Since poll() has
|
|
|
|
# no upper FD limit, it is suitable for use with Latch, which must handle
|
|
|
|
# no upper FD limit, it is suitable for use with Latch, which must handle
|
|
|
|
# FDs larger than select's limit during many-host runs. We want this
|
|
|
|
# FDs larger than select's limit during many-host runs. We want this
|
|
|
@ -1928,11 +1930,16 @@ class Poller(object):
|
|
|
|
def __init__(self):
|
|
|
|
def __init__(self):
|
|
|
|
self._rfds = {}
|
|
|
|
self._rfds = {}
|
|
|
|
self._wfds = {}
|
|
|
|
self._wfds = {}
|
|
|
|
self._pollobj = select.poll()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
def __repr__(self):
|
|
|
|
return '%s(%#x)' % (type(self).__name__, id(self))
|
|
|
|
return '%s(%#x)' % (type(self).__name__, id(self))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _update(self, fd):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Required by PollPoller subclass.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def readers(self):
|
|
|
|
def readers(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -1955,20 +1962,6 @@ class Poller(object):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
_readmask = select.POLLIN | select.POLLHUP
|
|
|
|
|
|
|
|
# TODO: no proof we dont need writemask too
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _update(self, fd):
|
|
|
|
|
|
|
|
mask = (((fd in self._rfds) and self._readmask) |
|
|
|
|
|
|
|
|
((fd in self._wfds) and select.POLLOUT))
|
|
|
|
|
|
|
|
if mask:
|
|
|
|
|
|
|
|
self._pollobj.register(fd, mask)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
self._pollobj.unregister(fd)
|
|
|
|
|
|
|
|
except KeyError:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def start_receive(self, fd, data=None):
|
|
|
|
def start_receive(self, fd, data=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Cause :meth:`poll` to yield `data` when `fd` is readable.
|
|
|
|
Cause :meth:`poll` to yield `data` when `fd` is readable.
|
|
|
@ -2004,22 +1997,27 @@ class Poller(object):
|
|
|
|
self._update(fd)
|
|
|
|
self._update(fd)
|
|
|
|
|
|
|
|
|
|
|
|
def _poll(self, timeout):
|
|
|
|
def _poll(self, timeout):
|
|
|
|
if timeout:
|
|
|
|
(rfds, wfds, _), _ = io_op(select.select,
|
|
|
|
timeout *= 1000
|
|
|
|
self._rfds,
|
|
|
|
|
|
|
|
self._wfds,
|
|
|
|
|
|
|
|
(), timeout
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
events, _ = io_op(self._pollobj.poll, timeout)
|
|
|
|
for fd in rfds:
|
|
|
|
for fd, event in events:
|
|
|
|
_vv and IOLOG.debug('%r: POLLIN for %r', self, fd)
|
|
|
|
if event & self._readmask:
|
|
|
|
|
|
|
|
_vv and IOLOG.debug('%r: POLLIN|POLLHUP for %r', self, fd)
|
|
|
|
|
|
|
|
data, gen = self._rfds.get(fd, (None, None))
|
|
|
|
data, gen = self._rfds.get(fd, (None, None))
|
|
|
|
if gen and gen < self._generation:
|
|
|
|
if gen and gen < self._generation:
|
|
|
|
yield data
|
|
|
|
yield data
|
|
|
|
if event & select.POLLOUT:
|
|
|
|
|
|
|
|
|
|
|
|
for fd in wfds:
|
|
|
|
_vv and IOLOG.debug('%r: POLLOUT for %r', self, fd)
|
|
|
|
_vv and IOLOG.debug('%r: POLLOUT for %r', self, fd)
|
|
|
|
data, gen = self._wfds.get(fd, (None, None))
|
|
|
|
data, gen = self._wfds.get(fd, (None, None))
|
|
|
|
if gen and gen < self._generation:
|
|
|
|
if gen and gen < self._generation:
|
|
|
|
yield data
|
|
|
|
yield data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if timeout:
|
|
|
|
|
|
|
|
timeout *= 1000
|
|
|
|
|
|
|
|
|
|
|
|
def poll(self, timeout=None):
|
|
|
|
def poll(self, timeout=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Block the calling thread until one or more FDs are ready for IO.
|
|
|
|
Block the calling thread until one or more FDs are ready for IO.
|
|
|
|