summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Ward <ian@excess.org>2017-08-22 14:30:46 -0400
committerGitHub <noreply@github.com>2017-08-22 14:30:46 -0400
commit09d1107ea7106f4f2b18cbe20a8b28e4618edeeb (patch)
tree61b17a8e9d84280b71ff245d96679a6b2a467f90
parentf406b0eb410ad3a732e28e613860dab4ac269c15 (diff)
parent6f9d01e527a69eb8ea58277b3e9488c96d76c8dc (diff)
downloadurwid-09d1107ea7106f4f2b18cbe20a8b28e4618edeeb.tar.gz
Merge pull request #248 from waveform80/master
Fix #246, fix #234
-rwxr-xr-xurwid/main_loop.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/urwid/main_loop.py b/urwid/main_loop.py
index 28577b2..ec9c411 100755
--- a/urwid/main_loop.py
+++ b/urwid/main_loop.py
@@ -27,6 +27,7 @@ import heapq
import select
import os
from functools import wraps
+from itertools import count
from weakref import WeakKeyDictionary
try:
@@ -442,7 +443,7 @@ class MainLoop(object):
sec = next_alarm[0] - time.time()
if sec > 0:
break
- tm, callback = next_alarm
+ tm, tie_break, callback = next_alarm
callback()
if self.event_loop._alarms:
@@ -589,6 +590,7 @@ class SelectEventLoop(object):
self._watch_files = {}
self._idle_handle = 0
self._idle_callbacks = {}
+ self._tie_break = count()
def alarm(self, seconds, callback):
"""
@@ -601,8 +603,9 @@ class SelectEventLoop(object):
callback -- function to call from event loop
"""
tm = time.time() + seconds
- heapq.heappush(self._alarms, (tm, callback))
- return (tm, callback)
+ handle = (tm, next(self._tie_break), callback)
+ heapq.heappush(self._alarms, handle)
+ return handle
def remove_alarm(self, handle):
"""
@@ -711,7 +714,7 @@ class SelectEventLoop(object):
self._did_something = False
elif tm is not None:
# must have been a timeout
- tm, alarm_callback = self._alarms.pop(0)
+ tm, tie_break, alarm_callback = heapq.heappop(self._alarms)
alarm_callback()
self._did_something = True