1 |
commit: 20a5f9cb0c9fec433df7256617bd8fe09892fafa |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Feb 8 04:24:47 2012 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Feb 8 04:24:47 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=20a5f9cb |
7 |
|
8 |
QueueScheduler: use timeout_add |
9 |
|
10 |
--- |
11 |
pym/_emerge/QueueScheduler.py | 51 +++++++++++++--------------------------- |
12 |
1 files changed, 17 insertions(+), 34 deletions(-) |
13 |
|
14 |
diff --git a/pym/_emerge/QueueScheduler.py b/pym/_emerge/QueueScheduler.py |
15 |
index a4ab328..91a2831 100644 |
16 |
--- a/pym/_emerge/QueueScheduler.py |
17 |
+++ b/pym/_emerge/QueueScheduler.py |
18 |
@@ -36,42 +36,25 @@ class QueueScheduler(PollScheduler): |
19 |
|
20 |
def run(self, timeout=None): |
21 |
|
22 |
- start_time = None |
23 |
- timed_out = False |
24 |
- remaining_timeout = timeout |
25 |
+ timeout_id = None |
26 |
if timeout is not None: |
27 |
- start_time = time.time() |
28 |
- |
29 |
- while self._schedule(): |
30 |
- self._schedule_wait(timeout=remaining_timeout) |
31 |
- if timeout is not None: |
32 |
- elapsed_time = time.time() - start_time |
33 |
- if elapsed_time < 0: |
34 |
- # The system clock has changed such that start_time |
35 |
- # is now in the future, so just assume that the |
36 |
- # timeout has already elapsed. |
37 |
- timed_out = True |
38 |
- break |
39 |
- remaining_timeout = timeout - 1000 * elapsed_time |
40 |
- if remaining_timeout <= 0: |
41 |
- timed_out = True |
42 |
- break |
43 |
- |
44 |
- if timeout is None or not timed_out: |
45 |
+ def timeout_callback(): |
46 |
+ raise StopIteration() |
47 |
+ timeout_id = self._timeout_add(timeout, timeout_callback) |
48 |
+ |
49 |
+ try: |
50 |
+ |
51 |
+ while self._schedule(): |
52 |
+ self._iteration() |
53 |
+ |
54 |
while self._running_job_count(): |
55 |
- self._schedule_wait(timeout=remaining_timeout) |
56 |
- if timeout is not None: |
57 |
- elapsed_time = time.time() - start_time |
58 |
- if elapsed_time < 0: |
59 |
- # The system clock has changed such that start_time |
60 |
- # is now in the future, so just assume that the |
61 |
- # timeout has already elapsed. |
62 |
- timed_out = True |
63 |
- break |
64 |
- remaining_timeout = timeout - 1000 * elapsed_time |
65 |
- if remaining_timeout <= 0: |
66 |
- timed_out = True |
67 |
- break |
68 |
+ self._iteration() |
69 |
+ |
70 |
+ except StopIteration: |
71 |
+ pass |
72 |
+ |
73 |
+ if timeout_id is not None: |
74 |
+ self._unregister(timeout_id) |
75 |
|
76 |
def _schedule_tasks(self): |
77 |
""" |