Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(62)

Delta Between Two Patch Sets: Lib/sched.py

Issue 22043: Use a monotonic clock to compute timeouts
Left Patch Set: Created 3 years, 4 months ago
Right Patch Set: Created 3 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/queue.py ('k') | Lib/socketserver.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 """A generally useful event scheduler class. 1 """A generally useful event scheduler class.
2 2
3 Each instance of this class manages its own queue. 3 Each instance of this class manages its own queue.
4 No multi-threading is implied; you are supposed to hack that 4 No multi-threading is implied; you are supposed to hack that
5 yourself, or use a single instance per application. 5 yourself, or use a single instance per application.
6 6
7 Each instance is parametrized with two functions, one that is 7 Each instance is parametrized with two functions, one that is
8 supposed to return the current time, one that is supposed to 8 supposed to return the current time, one that is supposed to
9 implement a delay. You can implement real-time scheduling by 9 implement a delay. You can implement real-time scheduling by
10 substituting time and sleep from built-in module time, or you can 10 substituting time and sleep from built-in module time, or you can
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 Events are named tuples with fields for: 155 Events are named tuples with fields for:
156 time, priority, action, arguments, kwargs 156 time, priority, action, arguments, kwargs
157 157
158 """ 158 """
159 # Use heapq to sort the queue rather than using 'sorted(self._queue)'. 159 # Use heapq to sort the queue rather than using 'sorted(self._queue)'.
160 # With heapq, two events scheduled at the same time will show in 160 # With heapq, two events scheduled at the same time will show in
161 # the actual order they would be retrieved. 161 # the actual order they would be retrieved.
162 with self._lock: 162 with self._lock:
163 events = self._queue[:] 163 events = self._queue[:]
164 return list(map(heapq.heappop, [events]*len(events))) 164 return list(map(heapq.heappop, [events]*len(events)))
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7