Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/_emerge/
Date: Thu, 16 Feb 2012 21:00:36
Message-Id: 1329425957.1979a6cdfcd8c6bae4565982d82d862be07ba5be.zmedico@gentoo
1 commit: 1979a6cdfcd8c6bae4565982d82d862be07ba5be
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Thu Feb 16 20:58:29 2012 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Thu Feb 16 20:59:17 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=1979a6cd
7
8 SubProcess: use child_watch_add
9
10 This fixes performance issues introduced by commit
11 9c664779a16f6cbca8a5ffe7f6b0c68572819723.
12
13 ---
14 pym/_emerge/SubProcess.py | 36 +++++++-----------------------------
15 1 files changed, 7 insertions(+), 29 deletions(-)
16
17 diff --git a/pym/_emerge/SubProcess.py b/pym/_emerge/SubProcess.py
18 index 01004a8..9c033c5 100644
19 --- a/pym/_emerge/SubProcess.py
20 +++ b/pym/_emerge/SubProcess.py
21 @@ -20,9 +20,6 @@ class SubProcess(AbstractPollTask):
22 # we've sent a kill signal to our subprocess.
23 _cancel_timeout = 1000 # 1 second
24
25 - # Poll interval for process exit status.
26 - _waitpid_interval = 1000 # 1 second
27 -
28 def _poll(self):
29 if self.returncode is not None:
30 return self.returncode
31 @@ -95,37 +92,18 @@ class SubProcess(AbstractPollTask):
32 return self.returncode
33
34 def _waitpid_loop(self):
35 - if not self._waitpid_cb():
36 - return
37 -
38 - timeout_id = self.scheduler.timeout_add(
39 - self._waitpid_interval, self._waitpid_cb)
40 + source_id = self.scheduler.child_watch_add(
41 + self.pid, self._waitpid_cb)
42 try:
43 while self.returncode is None:
44 self.scheduler.iteration()
45 finally:
46 - self.scheduler.source_remove(timeout_id)
47 -
48 - def _waitpid_cb(self):
49 - if self.returncode is not None:
50 - return False
51 - try:
52 - # With waitpid and WNOHANG, only check the
53 - # first element of the tuple since the second
54 - # element may vary (bug #337465).
55 - wait_retval = os.waitpid(self.pid, os.WNOHANG)
56 - except OSError as e:
57 - if e.errno != errno.ECHILD:
58 - raise
59 - del e
60 - self._set_returncode((self.pid, 1 << 8))
61 - return False
62 - else:
63 - if wait_retval[0] != 0:
64 - self._set_returncode(wait_retval)
65 - return False
66 + self.scheduler.source_remove(source_id)
67
68 - return True
69 + def _waitpid_cb(self, pid, condition, user_data):
70 + if pid != self.pid:
71 + raise AssertionError("expected pid %s, got %s" % (self.pid, pid))
72 + self._set_returncode((pid, condition))
73
74 def _orphan_process_warn(self):
75 pass