MCPcopy Create free account
hub / github.com/apache/cassandra-python-driver / TimerManager

Class TimerManager

cassandra/connection.py:1800–1841  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1798
1799
1800class TimerManager(object):
1801
1802 def __init__(self):
1803 self._queue = []
1804 self._new_timers = []
1805
1806 def add_timer(self, timer):
1807 """
1808 called from client thread with a Timer object
1809 """
1810 self._new_timers.append((timer.end, timer))
1811
1812 def service_timeouts(self):
1813 """
1814 run callbacks on all expired timers
1815 Called from the event thread
1816 :return: next end time, or None
1817 """
1818 queue = self._queue
1819 if self._new_timers:
1820 new_timers = self._new_timers
1821 while new_timers:
1822 heappush(queue, new_timers.pop())
1823
1824 if queue:
1825 now = time.time()
1826 while queue:
1827 try:
1828 timer = queue[0][1]
1829 if timer.finish(now):
1830 heappop(queue)
1831 else:
1832 return timer.end
1833 except Exception:
1834 log.exception("Exception while servicing timeout callback: ")
1835
1836 @property
1837 def next_timeout(self):
1838 try:
1839 return self._queue[0][0]
1840 except IndexError:
1841 pass

Callers 6

test_timer_collisionMethod · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
initialize_reactorMethod · 0.90
initialize_reactorMethod · 0.90

Calls

no outgoing calls

Tested by 1

test_timer_collisionMethod · 0.72