1 |
commit: 334c911923af24a7a7d977b28b24a09686e9906d |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Feb 8 03:21:58 2012 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Feb 8 03:34:16 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=334c9119 |
7 |
|
8 |
PollScheduler: add iteration method |
9 |
|
10 |
--- |
11 |
pym/_emerge/PollScheduler.py | 33 ++++++++++++++++++++++++--------- |
12 |
pym/_emerge/Scheduler.py | 6 +++--- |
13 |
2 files changed, 27 insertions(+), 12 deletions(-) |
14 |
|
15 |
diff --git a/pym/_emerge/PollScheduler.py b/pym/_emerge/PollScheduler.py |
16 |
index ab18f0d..9ddcd96 100644 |
17 |
--- a/pym/_emerge/PollScheduler.py |
18 |
+++ b/pym/_emerge/PollScheduler.py |
19 |
@@ -1,4 +1,4 @@ |
20 |
-# Copyright 1999-2011 Gentoo Foundation |
21 |
+# Copyright 1999-2012 Gentoo Foundation |
22 |
# Distributed under the terms of the GNU General Public License v2 |
23 |
|
24 |
import gzip |
25 |
@@ -24,7 +24,7 @@ from _emerge.PollSelectAdapter import PollSelectAdapter |
26 |
class PollScheduler(object): |
27 |
|
28 |
class _sched_iface_class(SlotObject): |
29 |
- __slots__ = ("idle_add", "io_add_watch", |
30 |
+ __slots__ = ("idle_add", "io_add_watch", "iteration", |
31 |
"output", "register", "schedule", |
32 |
"source_remove", "timeout_add", "unregister") |
33 |
|
34 |
@@ -59,6 +59,7 @@ class PollScheduler(object): |
35 |
self.sched_iface = self._sched_iface_class( |
36 |
idle_add=self._idle_add, |
37 |
io_add_watch=self._register, |
38 |
+ iteration=self._iteration, |
39 |
output=self._task_output, |
40 |
register=self._register, |
41 |
schedule=self._schedule_wait, |
42 |
@@ -268,14 +269,24 @@ class PollScheduler(object): |
43 |
if not event_handled: |
44 |
raise AssertionError("tight loop") |
45 |
|
46 |
- def _schedule_yield(self): |
47 |
+ def _iteration(self, *args): |
48 |
""" |
49 |
- Schedule for a short period of time chosen by the scheduler based |
50 |
- on internal state. Synchronous tasks should call this periodically |
51 |
- in order to allow the scheduler to service pending poll events. The |
52 |
- scheduler will call poll() exactly once, without blocking, and any |
53 |
- resulting poll events will be serviced. |
54 |
+ Like glib.MainContext.iteration(), runs a single iteration. |
55 |
+ @type may_block: bool |
56 |
+ @param may_block: if True the call may block waiting for an event |
57 |
+ (default is True). |
58 |
+ @rtype: bool |
59 |
+ @return: True if events were dispatched. |
60 |
""" |
61 |
+ |
62 |
+ may_block = True |
63 |
+ |
64 |
+ if args: |
65 |
+ if len(args) > 1: |
66 |
+ raise TypeError( |
67 |
+ "expected at most 1 argument (%s given)" % len(args)) |
68 |
+ may_block = args[0] |
69 |
+ |
70 |
event_handlers = self._poll_event_handlers |
71 |
events_handled = 0 |
72 |
|
73 |
@@ -283,7 +294,11 @@ class PollScheduler(object): |
74 |
return bool(events_handled) |
75 |
|
76 |
if not self._poll_event_queue: |
77 |
- self._poll(0) |
78 |
+ if may_block: |
79 |
+ timeout = 0 |
80 |
+ else: |
81 |
+ timeout = None |
82 |
+ self._poll(timeout=timeout) |
83 |
|
84 |
try: |
85 |
while event_handlers and self._poll_event_queue: |
86 |
|
87 |
diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py |
88 |
index b6b6586..e22ef46 100644 |
89 |
--- a/pym/_emerge/Scheduler.py |
90 |
+++ b/pym/_emerge/Scheduler.py |
91 |
@@ -1,4 +1,4 @@ |
92 |
-# Copyright 1999-2011 Gentoo Foundation |
93 |
+# Copyright 1999-2012 Gentoo Foundation |
94 |
# Distributed under the terms of the GNU General Public License v2 |
95 |
|
96 |
from __future__ import print_function |
97 |
@@ -81,7 +81,7 @@ class Scheduler(PollScheduler): |
98 |
|
99 |
class _iface_class(PollScheduler._sched_iface_class): |
100 |
__slots__ = ("fetch", |
101 |
- "scheduleSetup", "scheduleUnpack", "scheduleYield") |
102 |
+ "scheduleSetup", "scheduleUnpack") |
103 |
|
104 |
class _fetch_iface_class(SlotObject): |
105 |
__slots__ = ("log_file", "schedule") |
106 |
@@ -221,11 +221,11 @@ class Scheduler(PollScheduler): |
107 |
fetch=fetch_iface, output=self._task_output, |
108 |
idle_add=self._idle_add, |
109 |
io_add_watch=self._register, |
110 |
+ iteration=self._iteration, |
111 |
register=self._register, |
112 |
schedule=self._schedule_wait, |
113 |
scheduleSetup=self._schedule_setup, |
114 |
scheduleUnpack=self._schedule_unpack, |
115 |
- scheduleYield=self._schedule_yield, |
116 |
source_remove=self._unregister, |
117 |
timeout_add=self._timeout_add, |
118 |
unregister=self._unregister) |