add a check to ensure that the events loop doesn't continue indefinitely

This commit is contained in:
Damien Churchill 2010-10-10 19:51:50 +01:00
parent 8f7e307f33
commit f52e3c4aa0
1 changed files with 8 additions and 3 deletions

View File

@ -382,16 +382,21 @@ class EventQueue(object):
# Create a deferred to and check again in 100ms # Create a deferred to and check again in 100ms
d = Deferred() d = Deferred()
reactor.callLater(0.5, self._get_events, listener_id, d) reactor.callLater(0.1, self._get_events, listener_id, 0, d)
return d return d
def _get_events(self, listener_id, d): def _get_events(self, listener_id, count, d):
if listener_id in self.__queue: if listener_id in self.__queue:
queue = self.__queue[listener_id] queue = self.__queue[listener_id]
del self.__queue[listener_id] del self.__queue[listener_id]
d.callback(queue) d.callback(queue)
else: else:
reactor.callLater(0.1, self._get_events, listener_id, d) # Prevent this loop going on indefinitely incase a client leaves
# the page or disconnects uncleanly.
if count >= 3000:
d.callback(None)
else:
reactor.callLater(0.1, self._get_events, listener_id, count + 1, d)
def remove_listener(self, listener_id, event): def remove_listener(self, listener_id, event):
""" """