OLD | NEW |
1 #!/usr/bin/python | |
2 | |
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 3 # found in the LICENSE file. |
6 | 4 |
7 import copy | 5 import copy |
8 import threading | 6 import threading |
9 import time | 7 import time |
10 | 8 |
11 class TimerQueue(threading.Thread): | 9 class TimerQueue(threading.Thread): |
12 """Executes timers at a given interval. | 10 """Executes timers at a given interval. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 self.timer_queue_lock.acquire() | 76 self.timer_queue_lock.acquire() |
79 for timer in self.timers: | 77 for timer in self.timers: |
80 if timer['next time'] <= now: | 78 if timer['next time'] <= now: |
81 # Use * to break the list into separate arguments | 79 # Use * to break the list into separate arguments |
82 timer['method'](*timer['args']) | 80 timer['method'](*timer['args']) |
83 timer['next time'] += timer['interval'] | 81 timer['next time'] += timer['interval'] |
84 self.timer_queue_lock.release() | 82 self.timer_queue_lock.release() |
85 if self.terminate: | 83 if self.terminate: |
86 return | 84 return |
87 time.sleep(self.wait_time) | 85 time.sleep(self.wait_time) |
88 | |
OLD | NEW |