Ha ha, importing patch from #71 (thanks, Alexey, and fixing up the AUTHORS.
This commit is contained in:
3
AUTHORS
3
AUTHORS
@@ -65,4 +65,5 @@ Thanks To
|
||||
* Holger Krekel, websocket example small fix
|
||||
* mikepk, debugging MySQLdb/tpool issues
|
||||
* Malcolm Cleaton, patch for Event exception handling
|
||||
* Alexey Borzenkov, finding and fixing issue with Windows error detection (#53), finding and fixing error in websocket chat example (#70)
|
||||
* Alexey Borzenkov, for finding and fixing issues with Windows error detection (#66, #69), reducing dependencies in zeromq hub (#71)
|
||||
* Anonymous, finding and fixing error in websocket chat example (#70)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
from eventlet import patcher
|
||||
from eventlet.green import zmq
|
||||
from eventlet.hubs import poll, _threadlocal
|
||||
from eventlet.hubs.hub import BaseHub, noop
|
||||
from eventlet.hubs.poll import READ, WRITE
|
||||
from eventlet.hubs import _threadlocal
|
||||
from eventlet.hubs.hub import BaseHub, READ, WRITE, noop
|
||||
from eventlet.support import clear_sys_exc_info
|
||||
import sys
|
||||
|
||||
@@ -14,9 +13,7 @@ EXC_MASK = zmq.POLLERR
|
||||
READ_MASK = zmq.POLLIN
|
||||
WRITE_MASK = zmq.POLLOUT
|
||||
|
||||
class Hub(poll.Hub):
|
||||
|
||||
|
||||
class Hub(BaseHub):
|
||||
def __init__(self, clock=time.time):
|
||||
BaseHub.__init__(self, clock)
|
||||
self.poll = zmq.Poller()
|
||||
@@ -38,6 +35,15 @@ class Hub(poll.Hub):
|
||||
_threadlocal.context = zmq._Context(io_threads)
|
||||
return _threadlocal.context
|
||||
|
||||
def add(self, evtype, fileno, cb):
|
||||
listener = super(Hub, self).add(evtype, fileno, cb)
|
||||
self.register(fileno, new=True)
|
||||
return listener
|
||||
|
||||
def remove(self, listener):
|
||||
super(Hub, self).remove(listener)
|
||||
self.register(listener.fileno)
|
||||
|
||||
def register(self, fileno, new=False):
|
||||
mask = 0
|
||||
if self.listeners[READ].get(fileno):
|
||||
@@ -49,6 +55,18 @@ class Hub(poll.Hub):
|
||||
else:
|
||||
self.poll.unregister(fileno)
|
||||
|
||||
def remove_descriptor(self, fileno):
|
||||
super(Hub, self).remove_descriptor(fileno)
|
||||
try:
|
||||
self.poll.unregister(fileno)
|
||||
except (KeyError, ValueError, IOError, OSError):
|
||||
# raised if we try to remove a fileno that was
|
||||
# already removed/invalid
|
||||
pass
|
||||
|
||||
def do_poll(self, seconds):
|
||||
# zmq.Poller.poll expects milliseconds
|
||||
return self.poll.poll(seconds * 1000.0)
|
||||
|
||||
def wait(self, seconds=None):
|
||||
readers = self.listeners[READ]
|
||||
@@ -90,10 +108,3 @@ class Hub(poll.Hub):
|
||||
|
||||
if self.debug_blocking:
|
||||
self.block_detect_post()
|
||||
|
||||
|
||||
# def do_poll(self, seconds):
|
||||
# print 'poll: ', seconds
|
||||
# if seconds < 0:
|
||||
# seconds = 500
|
||||
# return self.poll.poll(seconds)
|
||||
@@ -287,7 +287,7 @@ class TestCheckingForZMQHub(TestCase):
|
||||
@skip_unless_zmq
|
||||
def setUp(self):
|
||||
self.orig_hub = zmq.get_hub_name_from_instance(get_hub())
|
||||
use_hub('poll')
|
||||
use_hub('selects')
|
||||
|
||||
def tearDown(self):
|
||||
use_hub(self.orig_hub)
|
||||
|
||||
Reference in New Issue
Block a user