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/portage/util/_async/
Date: Sun, 29 Apr 2018 06:09:14
Message-Id: 1524981538.be800bf0153a28ce034277d103a2021f93ac8b2e.zmedico@gentoo
1 commit: be800bf0153a28ce034277d103a2021f93ac8b2e
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Sun Apr 29 05:10:27 2018 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Sun Apr 29 05:58:58 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=be800bf0
7
8 PopenProcess: add_child_handler asyncio compat (bug 591760)
9
10 Migrate to asyncio's AbstractChildWatcher.add_child_handler
11 interface.
12
13 Bug: https://bugs.gentoo.org/591760
14
15 pym/portage/util/_async/PopenProcess.py | 31 +++++++++++++++++++------------
16 1 file changed, 19 insertions(+), 12 deletions(-)
17
18 diff --git a/pym/portage/util/_async/PopenProcess.py b/pym/portage/util/_async/PopenProcess.py
19 index 4344b1c9d..3fb60d527 100644
20 --- a/pym/portage/util/_async/PopenProcess.py
21 +++ b/pym/portage/util/_async/PopenProcess.py
22 @@ -1,4 +1,4 @@
23 -# Copyright 2012-2017 Gentoo Foundation
24 +# Copyright 2012-2018 Gentoo Foundation
25 # Distributed under the terms of the GNU General Public License v2
26
27 from _emerge.SubProcess import SubProcess
28 @@ -13,8 +13,7 @@ class PopenProcess(SubProcess):
29 self._registered = True
30
31 if self.pipe_reader is None:
32 - self._reg_id = self.scheduler.child_watch_add(
33 - self.pid, self._child_watch_cb)
34 + self._async_waitpid()
35 else:
36 try:
37 self.pipe_reader.scheduler = self.scheduler
38 @@ -24,17 +23,25 @@ class PopenProcess(SubProcess):
39 self.pipe_reader.start()
40
41 def _pipe_reader_exit(self, pipe_reader):
42 - self._reg_id = self.scheduler.child_watch_add(
43 - self.pid, self._child_watch_cb)
44 + self._async_waitpid()
45
46 - def _child_watch_cb(self, pid, condition, user_data=None):
47 - self._reg_id = None
48 - self._waitpid_cb(pid, condition)
49 - self.wait()
50 + def _async_waitpid(self):
51 + if self.returncode is None:
52 + self.scheduler._asyncio_child_watcher.\
53 + add_child_handler(self.pid, self._async_waitpid_cb)
54 + else:
55 + self._unregister()
56 + self._async_wait()
57
58 - def _set_returncode(self, wait_retval):
59 - SubProcess._set_returncode(self, wait_retval)
60 + def _async_waitpid_cb(self, pid, returncode):
61 if self.proc.returncode is None:
62 # Suppress warning messages like this:
63 # ResourceWarning: subprocess 1234 is still running
64 - self.proc.returncode = self.returncode
65 + self.proc.returncode = returncode
66 + self._unregister()
67 + self.returncode = returncode
68 + self._async_wait()
69 +
70 + def _poll(self):
71 + # Simply rely on _async_waitpid_cb to set the returncode.
72 + return self.returncode